Commit 6fe85496 authored by Tor Arne Vestbø's avatar Tor Arne Vestbø Committed by Tor Arne Vestbø

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.
parent c9d30849
......@@ -79,6 +79,10 @@ func listenAndServe(node *core.IpfsNode, addr ma.Multiaddr, handler http.Handler
// if node being closed before server exits, close server
case <-node.Closing():
log.Infof("server at %s terminating...", addr)
// make sure keep-alive connections do not keep the server running
server.InnerServer.SetKeepAlivesEnabled(false)
server.Shutdown <- true
outer:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment