@cryptotaxi247 / kubo / commits / cc830ff2e

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.

Tor Arne Vestbø committed Apr 17, 2015 at 18:45 UTC cc830ff2eec6832ab7e8e0663fdeb469a49873f9
1 file changed +12 -1
core/corehttp/corehttp.go
+12 -1
@@ -2,6 +2,7 @@ package corehttp
2
3 import (
4 "net/http"
5 + "time"
6
7 manners "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/braintree/manners"
8 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
77 case <-node.Closing():
78 log.Infof("server at %s terminating...", addr)
79 server.Shutdown <- true
79 - <-serverExited // now, DO wait until server exit
80 +
81 + outer:
82 + for {
83 + // wait until server exits
84 + select {
85 + case <-serverExited:
86 + break outer
87 + case <-time.After(5 * time.Second):
88 + log.Infof("waiting for server at %s to terminate...", addr)
89 + }
90 + }
91 }
92
93 log.Infof("server at %s terminated", addr)