agent: simplify shutdown timeout logging

Note that we are currently timing out every time. This still
needs to be investigated.
This commit is contained in:
Frank Schroeder 2017-05-31 09:41:58 +02:00
parent 30ba712857
commit d6c7404b34
No known key found for this signature in database
GPG Key ID: 4D65C6EAEC87DECD
1 changed files with 6 additions and 14 deletions

View File

@ -1065,27 +1065,19 @@ func (a *Agent) Shutdown() error {
// http server is HTTPS if TLSConfig is not nil and NextProtos does not only contain "h2" // http server is HTTPS if TLSConfig is not nil and NextProtos does not only contain "h2"
// the latter seems to be a side effect of HTTP/2 support in go 1.8. TLSConfig != nil is // the latter seems to be a side effect of HTTP/2 support in go 1.8. TLSConfig != nil is
// no longer sufficient to check for an HTTPS server. // no longer sufficient to check for an HTTPS server.
a.logger.Printf("[INFO] agent: Stopping %s server %s", a.logger.Printf("[INFO] agent: Stopping %s server %s", strings.ToUpper(srv.proto), srv.Addr)
strings.ToUpper(srv.proto), srv.Addr)
// old behavior: just die // old behavior: just die
// srv.Close() // srv.Close()
// graceful shutdown // 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(), 100*time.Millisecond)
defer cancel() defer cancel()
done := make(chan struct{})
go func() {
srv.Shutdown(ctx) srv.Shutdown(ctx)
close(done) <-ctx.Done()
}() if ctx.Err() == context.DeadlineExceeded {
select { a.logger.Printf("[WARN] agent: Timeout stopping %s server %s", strings.ToUpper(srv.proto), srv.Addr)
case <-done:
// server down within timeout
case <-ctx.Done():
a.logger.Printf("[WARN] agent: Timeout stopping %s server %s",
strings.ToUpper(srv.proto), srv.Addr)
} }
} }
a.logger.Println("[INFO] agent: Waiting for endpoints to shut down") a.logger.Println("[INFO] agent: Waiting for endpoints to shut down")