提交 6fe85496 作者: Tor Arne Vestbø 提交者: 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.
上级 c9d30849
...@@ -79,6 +79,10 @@ func listenAndServe(node *core.IpfsNode, addr ma.Multiaddr, handler http.Handler ...@@ -79,6 +79,10 @@ func listenAndServe(node *core.IpfsNode, addr ma.Multiaddr, handler http.Handler
// if node being closed before server exits, close server // if node being closed before server exits, close server
case <-node.Closing(): case <-node.Closing():
log.Infof("server at %s terminating...", addr) 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 server.Shutdown <- true
outer: outer:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论