Skip to content

Commit

Permalink
redo server and graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
puellanivis committed May 7, 2019
1 parent bf47f3f commit 1a086ec
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions dashcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,23 @@ func main() {
srv := &http.Server{}

go func() {
<-ctx.Done()

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Serve(l); err != nil {
if err != http.ErrServerClosed {
glog.Error("http.Server.Serve: ", err)
}
}
}()

srv.Shutdown(ctx)
<-ctx.Done()

l.Close()
}()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if err := srv.Serve(l); err != nil {
if err != http.ErrServerClosed {
glog.Error(err)
}
if err := srv.Shutdown(ctx); err != nil {
glog.Error("http.Server.Shutdown: ", err)
}

l.Close()
}()
}

Expand Down

0 comments on commit 1a086ec

Please sign in to comment.