Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit graceful shutdown duration #3093

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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