Improve server shutdown
Less likely to corrupt data now.
This commit is contained in:
parent
0fcc67c121
commit
7847236dbc
14
main.go
14
main.go
@ -66,16 +66,16 @@ func main() {
|
||||
})
|
||||
|
||||
server := &http.Server{Addr: listenAddr}
|
||||
go func() {
|
||||
if err := http.ListenAndServe(listenAddr, nil); err != nil &&
|
||||
err != http.ErrServerClosed {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}()
|
||||
errs := make(chan error, 1)
|
||||
go func() { errs <- server.ListenAndServe() }()
|
||||
|
||||
sig := make(chan os.Signal)
|
||||
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-sig
|
||||
select {
|
||||
case <-sig:
|
||||
case err := <-errs:
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
// For simplicity, we'll wait for everything to finish, including snapshots.
|
||||
if err := server.Shutdown(context.Background()); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user