gpt4 book ai didi

go - Golang 优雅关闭 HTTP 需要多长时间?

转载 作者:IT王子 更新时间:2023-10-29 01:44:44 25 4
gpt4 key购买 nike

根据 https://golang.org/pkg/net/http/#Server.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, then the context's error is returned.

“然后无限期地等待连接返回空闲状态然后关闭”到底是什么意思?我是否应该期望上下文超时通常应该在此正常关闭完成之前发生,给定秒级的超时?

最佳答案

waiting indefinitely for connections to return to idle

指的是已经作为传入连接的一部分被调用的 HTTP 处理程序。所有这些处理程序都需要关闭/返回,通常通过调用 w.Write or w.WriteHeader 来完成。

关于go - Golang 优雅关闭 HTTP 需要多长时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44363096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com