From 0fa03b03e0eb26adf8dd774ceffc0fb956582ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Ga=C4=87e=C5=A1a?= Date: Wed, 16 Jun 2021 18:40:28 +0200 Subject: [PATCH] Limit graceful shutdown duration --- server/server.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/server.go b/server/server.go index 0c9c4751..4c123241 100644 --- a/server/server.go +++ b/server/server.go @@ -37,6 +37,8 @@ type Server struct { Handler http.Handler } +const timeoutGracefulShutdown = 5 * time.Second + // ListenAndServe initializes a server to respond to HTTP network requests. func (s Server) ListenAndServe(ctx context.Context) error { if s.Acme { @@ -60,7 +62,7 @@ func (s Server) listenAndServe(ctx context.Context) error { g.Go(func() error { <-ctx.Done() - ctxShutdown, cancelFunc := context.WithTimeout(context.Background(), time.Minute) + ctxShutdown, cancelFunc := context.WithTimeout(context.Background(), timeoutGracefulShutdown) defer cancelFunc() return s1.Shutdown(ctxShutdown) @@ -94,7 +96,7 @@ func (s Server) listenAndServeTLS(ctx context.Context) error { <-ctx.Done() var gShutdown errgroup.Group - ctxShutdown, cancelFunc := context.WithTimeout(context.Background(), time.Minute) + ctxShutdown, cancelFunc := context.WithTimeout(context.Background(), timeoutGracefulShutdown) defer cancelFunc() gShutdown.Go(func() error { @@ -142,7 +144,7 @@ func (s Server) listenAndServeAcme(ctx context.Context) error { <-ctx.Done() var gShutdown errgroup.Group - ctxShutdown, cancelFunc := context.WithTimeout(context.Background(), time.Minute) + ctxShutdown, cancelFunc := context.WithTimeout(context.Background(), timeoutGracefulShutdown) defer cancelFunc() gShutdown.Go(func() error {