开启地域容灾后,网络错误变成 AttributeError,且不会重试
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start in tencentcloud/common/abstract_client.py at AbstractClient._call_with_region_breaker, followed by _call_once, call, call_json and _call_and_deserialize to see how the returned value reaches _check_status. Reproduce with an endpoint pointing at a closed local port and StandardRetryer(max_attempts=3, backoff_fn=lambda n: 0), comparing disable_region_breaker True and False. Done means ClientNetworkError propagates in both modes, attempts equal max_attempts, and the breaker records the failure; add the unit test mocking send_request.
Written by the indexing model from the issue text.
Description
现象
按 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。
- Dominant language
- Python
- Stars
- 717
- Forks
- 254
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TencentCloud/tencentcloud-sdk-python
-
Incompatibility with Python 3.14May be free again A pull request for this issue was closed without being merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 65/100
TencentCloud/tencentcloud-sdk-python#229 · 2 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
-
return in finally swallows exceptionsPossibly taken @sesky4 claimed this 657 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 48/100
TencentCloud/tencentcloud-sdk-python#195 · 1 comment ·
-
一句话识别异步调用Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
TencentCloud/tencentcloud-sdk-python#191 · 4 comments ·
All issues in TencentCloud/tencentcloud-sdk-python
Similar issues
-
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)Possibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
pallets-eco/croniter#309 ·
Maintainers usually reply within 1 day
-
[Bug]: MLX text downloads omit the requested Hub token and cache directoryPossibly taken @abhijithneilabraham claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vllm-project/vllm-metal#1423 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
linkedin/Liger-Kernel#1693 ·
Maintainers usually reply within 3 days
-
Growl: a server-rejected notification is reported as a successPossibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gke-labs/kube-agents#7441 ·
Maintainers usually reply within 1 day