Skip to content

Commit ec9f6c5

Browse files
authored
Merge pull request #113 from shihanng/graceful
Use buffered channel for graceful shutdown
2 parents 3b9fa82 + 623577e commit ec9f6c5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cookbook/graceful-shutdown/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ func main() {
2727
}
2828
}()
2929

30-
// Wait for interrupt signal to gracefully shutdown the server with
31-
// a timeout of 10 seconds.
32-
quit := make(chan os.Signal)
30+
// Wait for interrupt signal to gracefully shutdown the server with a timeout of 10 seconds.
31+
// Use a buffered channel to avoid missing signals as recommended for signal.Notify
32+
quit := make(chan os.Signal, 1)
3333
signal.Notify(quit, os.Interrupt)
3434
<-quit
3535
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)

0 commit comments

Comments
 (0)