Skip to content

Commit

Permalink
shut down the HTTP server immediately on SIG{INT,TERM}
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Oct 7, 2024
1 parent 307f1ad commit 0531514
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions fed/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ func (l *Listener) ListenAndServe(ctx context.Context) error {
wg.Add(1)
go func() {
<-serverCtx.Done()
server.Shutdown(context.Background())

// shut down gracefully only on reload
if ctx.Err() == nil {
slog.Info("Shutting down server")
server.Shutdown(ctx)
}

server.Close()
wg.Done()
}()

Expand All @@ -129,7 +136,6 @@ func (l *Listener) ListenAndServe(ctx context.Context) error {
for {
select {
case <-serverCtx.Done():
server.Shutdown(context.Background())
return

case event, ok := <-w.Events:
Expand Down

0 comments on commit 0531514

Please sign in to comment.