Skip to content

Commit

Permalink
fix http server graceful shutdown (#571)
Browse files Browse the repository at this point in the history
as golang's http doc point out

```
ListenAndServe always returns a non-nil error. After Shutdown or Close
```

`log.Fatal(httpSrv.ListenAndServe())` will cause server exit immediately
with code 1, without waiting 5s for graceful shutdown.
  • Loading branch information
phosae authored May 17, 2024
1 parent cdd4e73 commit ef57614
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/picoshare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func main() {
httpSrv := http.Server{Addr: fmt.Sprintf(":%s", port), Handler: h}
go func() {
log.Printf("listening on %s", port)
log.Fatal(httpSrv.ListenAndServe())
log.Printf("http server exit: %s", httpSrv.ListenAndServe())
}()
<-stop
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand Down

0 comments on commit ef57614

Please sign in to comment.