@@ -35,7 +35,13 @@ func shutDown(ctx context.Context, s *http.Server, waitForShutdownCompletion cha
3535 signal .Notify (sigch , syscall .SIGINT , syscall .SIGTERM )
3636 sig := <- sigch
3737 log .Printf ("Got signal: %v . Server shutting down." , sig )
38- if err := s .Shutdown (ctx ); err != nil {
38+
39+ childCtx , cancel := context .WithTimeout (
40+ ctx , 30 * time .Second ,
41+ )
42+ defer cancel ()
43+
44+ if err := s .Shutdown (childCtx ); err != nil {
3945 log .Printf ("Error during shutdown: %v" , err )
4046 }
4147 waitForShutdownCompletion <- struct {}{}
@@ -48,11 +54,6 @@ func main() {
4854 }
4955
5056 waitForShutdownCompletion := make (chan struct {})
51- ctx , cancel := context .WithTimeout (
52- context .Background (), 30 * time .Second ,
53- )
54- defer cancel ()
55-
5657 mux := http .NewServeMux ()
5758 mux .HandleFunc ("/api/users/" , handleUserAPI )
5859
@@ -61,7 +62,7 @@ func main() {
6162 Handler : mux ,
6263 }
6364
64- go shutDown (ctx , & s , waitForShutdownCompletion )
65+ go shutDown (context . Background () , & s , waitForShutdownCompletion )
6566
6667 err := s .ListenAndServe ()
6768 log .Print (
0 commit comments