开启地域容灾后,网络错误变成 AttributeError,且不会重试
还没有人认领这个 Issue。
评估
调研方向
从 tencentcloud/common/abstract_client.py 中的 AbstractClient._call_with_region_breaker 开始,接着查看 _call_once、call、call_json 和 _call_and_deserialize,了解返回值如何到达 _check_status。用一个指向已关闭本地端口的 endpoint 和 StandardRetryer(max_attempts=3, backoff_fn=lambda n: 0) 复现,比较 disable_region_breaker 为 True 和 False 的情况。完成意味着 ClientNetworkError 在两种模式下都会传播,尝试次数等于 max_attempts,且 breaker 记录该失败;添加 mock send_request 的单元测试。
由索引模型根据 Issue 内容生成。
描述
现象
按 README「地域容灾」一节打开地域容灾(client_profile.disable_region_breaker = False)后,只要请求本身失败(连接被拒、超时、DNS 失败等,ApiRequest.send_request 抛出 ClientNetworkError),调用方拿到的不是 TencentCloudSDKException,而是:
AttributeError: 'NoneType' object has no attribute 'status_code'
同时配置的 retryer(如 StandardRetryer)也不会重试,因为它只看得到 AttributeError。
原因
AbstractClient._call_with_region_breaker 在 except TencentCloudSDKException 里记录完熔断器的成功/失败之后没有重新抛出,函数返回 None;call / call_json / _call_and_deserialize 里的 _call_once 接着对这个 None 调 _check_status,于是变成 AttributeError。关闭地域容灾(默认)时走的是另一条分支,网络错误会正常以 ClientNetworkError 抛出并被重试。
怎么触发
地域容灾本来就是为主域名请求失败的场景准备的,所以正好是在它该起作用的时候出问题:
cp = ClientProfile(disable_region_breaker=False,
retryer=StandardRetryer(max_attempts=3))
client = CommonClient("cvm", "2017-03-12", cred, "ap-guangzhou", profile=cp)
try:
client.call_json("DescribeRegions", {})
except TencentCloudSDKException as e: # 接不到
...
复现
master(91bcb61,release 3.1.211),macOS,Python 3.9。把 endpoint 指向一个不监听的本地端口(连接被拒),StandardRetryer(max_attempts=3, backoff_fn=lambda n: 0),统计实际发出的请求次数,分别关/开地域容灾:
disable_region_breaker=True attempts=3 -> TencentCloudSDKException: code:ClientNetworkError ...
disable_region_breaker=False attempts=1 -> AttributeError: 'NoneType' object has no attribute 'status_code'
建议
在 except 分支里记录完熔断器状态后 raise,让异常照常往上走。2024 年的 #183 提过同样的一行改动,后来被作者自己关掉了,PR 上没有评审记录;当前 master 上问题还在。我这边加了一个单测(mock send_request 抛 ClientNetworkError,关/开地域容灾两种情况都断言抛出 ClientNetworkError、重试次数等于 max_attempts、开启时熔断器记了相应的失败次数),可以提一个 PR。
- 主要语言
- Python
- 星标
- 717
- 派生
- 254
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TencentCloud/tencentcloud-sdk-python 的其他 Issue
-
Incompatibility with Python 3.14可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 1/5 1 小时以内 新手友好度 65/100
TencentCloud/tencentcloud-sdk-python#229 · 2 个 reaction ·
-
难度 5/5 一周以上 新手友好度 20/100
-
难度 5/5 一周以上 新手友好度 15/100
-
return in finally swallows exceptions可能已有人在做 @sesky4 于 657 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 48/100
TencentCloud/tencentcloud-sdk-python#195 · 1 条评论 ·
-
一句话识别异步调用未关闭
难度 5/5 一周以上 新手友好度 15/100
TencentCloud/tencentcloud-sdk-python#191 · 4 条评论 ·
查看 TencentCloud/tencentcloud-sdk-python 的全部 Issue
相似的 Issue
-
day_or=True union silently becomes the ISC cron AND bug when a day field expands to its full range (e.g. '0 0 */1 * */2' fires only Sun/Tue/Thu/Sat)可能已有人在做 @rahul05ranjan 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
pallets-eco/croniter#309 ·
维护者通常 1 天内回复
-
[Bug]: MLX text downloads omit the requested Hub token and cache directory可能已有人在做 @abhijithneilabraham 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
vllm-project/vllm-metal#1423 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
linkedin/Liger-Kernel#1693 ·
维护者通常 3 天内回复
-
Growl: a server-rejected notification is reported as a success可能已有人在做 @rahul05ranjan 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
gke-labs/kube-agents#7441 ·
维护者通常 1 天内回复