Skip to content

Commit 46ddd42

Browse files
jjba23J. J. Bigorrathinkerou
authored
Fixes to the graceful shutdown example (#2552)
* Change error comparison to use errors.Is() and add a line of whitespace before the if statement on graceful shutdown * Change from log.Fatalf to log.Printf to ensure the graceful shutdown actually works Co-authored-by: J. J. Bigorra <[email protected]> Co-authored-by: thinkerou <[email protected]>
1 parent f4bc259 commit 46ddd42

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,8 +1793,8 @@ func main() {
17931793
// Initializing the server in a goroutine so that
17941794
// it won't block the graceful shutdown handling below
17951795
go func() {
1796-
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
1797-
log.Fatalf("listen: %s\n", err)
1796+
if err := srv.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) {
1797+
log.Printf("listen: %s\n", err)
17981798
}
17991799
}()
18001800

@@ -1812,6 +1812,7 @@ func main() {
18121812
// the request it is currently handling
18131813
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
18141814
defer cancel()
1815+
18151816
if err := srv.Shutdown(ctx); err != nil {
18161817
log.Fatal("Server forced to shutdown:", err)
18171818
}

0 commit comments

Comments
 (0)