Skip to content

Commit 513313f

Browse files
authored
Server: Allow second SIGINT / SIGTERM to force exit (#31)
Before: 1. Boot the server 2. Press `Ctrl + C` once to trigger graceful shutdown 3. Press `Ctrl + C` again. This has no effect. You must wait for the server to shut down After: 1. Boot the server 2. Press `Ctrl + C` once to trigger graceful shutdown 3. Press `Ctrl + C` again to force exit immediately
1 parent 53d7fed commit 513313f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

internal/http/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ func ListenAndServe(a *app.App) error {
5050
close(errCh)
5151
}()
5252

53-
quit := make(chan os.Signal, 1)
54-
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
53+
sigCtx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
54+
defer stop()
5555

5656
select {
57-
case sig := <-quit:
58-
a.Logger.Info("shutting down", "signal", sig.String())
57+
case <-sigCtx.Done():
58+
a.Logger.Info("shutting down", "cause", context.Cause(sigCtx))
59+
stop()
5960
case err := <-errCh:
6061
if err != nil {
6162
sentry.CaptureException(err)

0 commit comments

Comments
 (0)