go - 我可以使用 Context().Done() 来检查服务器关闭吗?

标签 go

正如 golang http 包文档所说,http.ServerShutdown() 调用后直到所有处理程序完成后才会关闭。如果处理程序花费的时间太长,上下文将过期,并且 Shutdown() 返回错误。当 server.Shutdown() 被调用时,我应该怎么做才能强制处理程序立即返回? http.RequestContext().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/

相关文章:

go - 使用 Golang 对 Redshift 数据库进行 CRUD 操作

angularjs - Golang 和 AngularJS 模板冲突

string - Golang将字符串转换为int64

go - 如何导入 CSV 并保存在数据库中

multithreading - 这个 Go 代码是线程安全的还是我需要一个互斥体?

go - 使用 channel 退出永久循环 - Go Playground 的问题

ssl - 如何在 Go ReverseProxy 中使用 TLS?

go - 如何使用 golang libp2p 流向多个主机发送数据?

go - 如何使用 mgo 从嵌套接口(interface)的 mongo 解码 bson?

戈朗 : cannot install package zvelo/ttlru