From cc830ff2eec6832ab7e8e0663fdeb469a49873f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 17 Apr 2015 18:45:58 +0200 Subject: [PATCH] corehttp: log when server takes a long time to shut down The server may stay alive for quite a while due to waiting on open connections to close before shutting down. We should find ways to terminate these connections in a more controlled manner, but in the meantime it's helpful to be able to see why a shutdown of the ipfs daemon is taking so long. --- core/corehttp/corehttp.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/corehttp/corehttp.go b/core/corehttp/corehttp.go index 2c679eb1f..38e13a882 100644 --- a/core/corehttp/corehttp.go +++ b/core/corehttp/corehttp.go @@ -2,6 +2,7 @@ package corehttp import ( "net/http" + "time" manners "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/braintree/manners" ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" @@ -76,7 +77,17 @@ func listenAndServe(node *core.IpfsNode, addr ma.Multiaddr, handler http.Handler case <-node.Closing(): log.Infof("server at %s terminating...", addr) server.Shutdown <- true - <-serverExited // now, DO wait until server exit + + outer: + for { + // wait until server exits + select { + case <-serverExited: + break outer + case <-time.After(5 * time.Second): + log.Infof("waiting for server at %s to terminate...", addr) + } + } } log.Infof("server at %s terminated", addr)