正如 golang http
包文档所说,http.Server
在 Shutdown()
调用后直到所有处理程序完成后才会关闭。如果处理程序花费的时间太长,上下文将过期,并且 Shutdown()
返回错误。当 server.Shutdown()
被调用时,我应该怎么做才能强制处理程序立即返回? http.Request
的 Context().Done()
会在调用 server.ShutDown()
后关闭吗?
最佳答案
没有。如果你read the docs ,它准确地解释了 Shutdown
的作用,明确说明它不中断事件连接(添加了强调):
Shutdown gracefully shuts down the server without interrupting any active connections. Shutdown works by first closing all open listeners, then closing all idle connections, and then waiting indefinitely for connections to return to idle and then shut down. If the provided context expires before the shutdown is complete, Shutdown returns the context's error, otherwise it returns any error returned from closing the Server's underlying Listener(s).
关于go - 我可以使用 Context().Done() 来检查服务器关闭吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49851014/