diff options
Diffstat (limited to 'pkg/worker/http.go')
-rw-r--r-- | pkg/worker/http.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/pkg/worker/http.go b/pkg/worker/http.go index 1d56f86..973775e 100644 --- a/pkg/worker/http.go +++ b/pkg/worker/http.go @@ -16,11 +16,23 @@ func NewServerTask(server *http.Server) *ServerTask { } func (self *ServerTask) Start(ctx context.Context) error { + done := make(chan error) + go func() { - // nolint: errcheck - self.server.ListenAndServe() + done <- self.server.ListenAndServe() }() - <-ctx.Done() - return self.server.Shutdown(ctx) + select { + // if ListenAndServe error for something other than context.Canceled + //(e.g.: address already in use) it trigger done to return sonner with + // the return error + case err := <-done: + return err + + // in case of context canceled it will manually trigger the server to + // shutdown, and return its error, which is most cases, but not limited, is + // context.Canceled. + case <-ctx.Done(): + return self.server.Shutdown(ctx) + } } |