知识卡片
默认客户端没有总请求时限
http.Get等便利函数使用DefaultClient,其Timeout零值不设置整个请求的总时限。遇到迟迟不结束的请求,调用可能长时间占住资源,应按场景配置Client超时或请求上下文,并复用客户端。这个零值不表示连接的每个阶段都没有任何其他限制,也不等于请求一定永久阻塞。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Loose Coupling · 查看原书依据
the default timeout value is 0, which Go interprets as “no timeout”. Okay, so Go’s default HTTP client will never time out. Is that a problem? Usually not, but what if it connects to a server that doesn’t respond and doesn’t close the connection? The result would be an especially nasty and non-deterministic memory leak.
参考来源
- 位置:《Cloud Native Go》第08章《Loose Coupling》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch08.xhtml)
- 结论依据:http.Get等便利函数使用DefaultClient,其Timeout零值不设置整个请求的总时限。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:the default timeout value is 0, which Go interprets as “no timeout”. Okay, so Go’s default HTTP client will never time out. Is that a problem? Usually not, but what if it connects to a server that doesn’t respond and doesn’t close the connection? The result would be an especially nasty and non-deterministic memory leak.