diff --git a/server/server.go b/server/server.go index 3c27e9f..581b32f 100644 --- a/server/server.go +++ b/server/server.go @@ -44,10 +44,8 @@ func (s Server) listenAndServe(ctx context.Context) error { Handler: s.Handler, } g.Go(func() error { - select { - case <-ctx.Done(): - return s1.Shutdown(ctx) - } + <-ctx.Done() + return s1.Shutdown(context.Background()) }) g.Go(func() error { return s1.ListenAndServe() @@ -75,12 +73,18 @@ func (s Server) listenAndServeTLS(ctx context.Context) error { ) }) g.Go(func() error { - select { - case <-ctx.Done(): - s1.Shutdown(ctx) - s2.Shutdown(ctx) - return nil - } + <-ctx.Done() + + var gShutdown errgroup.Group + + gShutdown.Go(func() error { + return s1.Shutdown(context.Background()) + }) + gShutdown.Go(func() error { + return s2.Shutdown(context.Background()) + }) + + return gShutdown.Wait() }) return g.Wait() } @@ -114,12 +118,18 @@ func (s Server) listenAndServeAcme(ctx context.Context) error { return s2.ListenAndServeTLS("", "") }) g.Go(func() error { - select { - case <-ctx.Done(): - s1.Shutdown(ctx) - s2.Shutdown(ctx) - return nil - } + <-ctx.Done() + + var gShutdown errgroup.Group + + gShutdown.Go(func() error { + return s1.Shutdown(context.Background()) + }) + gShutdown.Go(func() error { + return s2.Shutdown(context.Background()) + }) + + return gShutdown.Wait() }) return g.Wait() }