Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
fix: check signal in goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Jun 25, 2024
1 parent 5a7d002 commit df372b4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ func main() {
}
}()

// wait for exit signal
signal := <-osSignalChannel
logger.Logger.WithField("signal", signal).Info("Received OS signal")
cancel()
var signal os.Signal
go func() {
// wait for exit signal
signal = <-osSignalChannel
logger.Logger.WithField("signal", signal).Info("Received OS signal")
cancel()
}()

//handle graceful shutdown
<-ctx.Done()
logger.Logger.WithField("signal", signal).Info("Context Done")
logger.Logger.Info("Shutting down echo server...")
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand Down

0 comments on commit df372b4

Please sign in to comment.