@cryptotaxi247 / kubo / commits / 6fe85496f

corehttp: disable HTTP keep-alive when shutting down server

Once the server is asked to shut down, we stop accepting new connections, but the 'manners' graceful shutdown will wait for all existing connections closed to close before finishing. For keep-alive connections this will never happen unless the client detects that the server is shutting down through the ipfs API itself, and closes the connection in response. This is a problem e.g. with the webui's connections visualization, which polls the swarm/peers endpoint once a second, and never detects that the API server was shut down. We can mitigate this by telling the server to disable keep-alive, which will add a 'Connection: close' header to the next HTTP response on the connection. A well behaving client should then treat that correspondingly by closing the connection. Unfortunately this doesn't happen immediately in all cases, presumably depending on the keep-alive timeout of the browser that set up the connection, but it's at least a step in the right direction.

Tor Arne Vestbø committed Apr 17, 2015 at 18:46 UTC 6fe85496f5dcad75bdb2b72a187f6503397627e6
1 file changed +4
core/corehttp/corehttp.go
+4
@@ -79,6 +79,10 @@ func listenAndServe(node *core.IpfsNode, addr ma.Multiaddr, handler http.Handler
79 // if node being closed before server exits, close server
80 case <-node.Closing():
81 log.Infof("server at %s terminating...", addr)
82 +
83 + // make sure keep-alive connections do not keep the server running
84 + server.InnerServer.SetKeepAlivesEnabled(false)
85 +
86 server.Shutdown <- true
87
88 outer: