Skip to content

Commit

Permalink
feat: handle timeout when shutting down http server
Browse files Browse the repository at this point in the history
  • Loading branch information
thoas committed Sep 26, 2023
1 parent 50cf3a2 commit a26a09e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,15 @@ func (s *HTTPServer) Run(ctx context.Context) error {
case err := <-cerr:
return err
case <-ctx.Done():
s.processor.Logger.Debug("Shutdown HTTP server")
return srv.Shutdown(context.Background())
s.processor.Logger.Debug("Shutting down HTTP server")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
return err
}
select {
case <-ctx.Done():
return nil
}
}
}

0 comments on commit a26a09e

Please sign in to comment.