Skip to content

Commit

Permalink
Merge pull request #3093 from drone/graceful-shutdown-timeout
Browse files Browse the repository at this point in the history
Limit graceful shutdown duration
  • Loading branch information
TP Honey committed Jun 17, 2021
2 parents 6b30b18 + 0fa03b0 commit 4dc03b5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4dc03b5

Please sign in to comment.