Skip to content

Commit

Permalink
Cleaner shutdown for the HTTP server goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
susji committed Apr 10, 2024
1 parent 3890493 commit 46eac6b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/ruuvimetrics/ruuvimetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ func main() {
s := &http.Server{Addr: l}
go func() {
defer wg.Done()
rc := 0
err := s.ListenAndServe()
if errors.Is(err, http.ErrServerClosed) {
log.Println("http server shutting down")
log.Println("HTTP server closed - reader probably shut down")
} else if err != nil {
log.Println("http server errored:", err)
os.Exit(1)
log.Println("HTTP server errored:", err)
rc = 1
}
os.Exit(rc)
}()
go func() {
defer wg.Done()
Expand Down

0 comments on commit 46eac6b

Please sign in to comment.