Improve server shutdown

Less likely to corrupt data now.
This commit is contained in:
Přemysl Eric Janouch 2019-04-19 12:30:32 +02:00
parent 0fcc67c121
commit 7847236dbc
Signed by: p
GPG Key ID: A0420B94F92B9493

14
main.go
View File

@ -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 {