agent: fix graceful http server shutdown

This commit is contained in:
Frank Schroeder 2017-06-02 22:21:51 +02:00 committed by Frank Schröder
parent 9779f7ef02
commit 92b2192b75
1 changed files with 1 additions and 6 deletions

View File

@ -1077,15 +1077,10 @@ func (a *Agent) Shutdown() error {
// no longer sufficient to check for an HTTPS server.
a.logger.Printf("[INFO] agent: Stopping %s server %s", strings.ToUpper(srv.proto), srv.Addr)
// old behavior: just die
// srv.Close()
// graceful shutdown
// todo(fs): we are timing out every time. Need to find out why.
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
srv.Shutdown(ctx)
<-ctx.Done()
if ctx.Err() == context.DeadlineExceeded {
a.logger.Printf("[WARN] agent: Timeout stopping %s server %s", strings.ToUpper(srv.proto), srv.Addr)
}