From db3dbcce3ac673113ba48967cf1d656606a41dc3 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 29 Nov 2019 06:10:08 -0800 Subject: [PATCH] Print goroutines when shutdown hangs (#8574) --- cmd/http/server.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/http/server.go b/cmd/http/server.go index 7a47c02ba..836f6bb12 100644 --- a/cmd/http/server.go +++ b/cmd/http/server.go @@ -19,7 +19,9 @@ package http import ( "crypto/tls" "errors" + "io/ioutil" "net/http" + "runtime/pprof" "sync" "sync/atomic" "time" @@ -137,6 +139,13 @@ func (srv *Server) Shutdown() error { for { select { case <-shutdownTimer.C: + // Write all running goroutines. + tmp, err := ioutil.TempFile("", "minio-goroutines-*.txt") + if err == nil { + _ = pprof.Lookup("goroutine").WriteTo(tmp, 1) + tmp.Close() + return errors.New("timed out. some connections are still active. doing abnormal shutdown. goroutines written to " + tmp.Name()) + } return errors.New("timed out. some connections are still active. doing abnormal shutdown") case <-ticker.C: if atomic.LoadInt32(&srv.requestCount) <= 0 {