Container credentials client sleeps after the final failed attempt
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
从 HttpCredentialsClient.get_credentials() 开始,检查 issue 中描述的异常处理重试循环。添加或更新一个回归测试,对 asyncio.sleep 进行 mock,并验证两次尝试产生一次 sleep,而最终失败会立即抛出;terminal SmithyIdentityError 应保持不变。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
HttpCredentialsClient.get_credentials() waits for the retry delay after every failed attempt, including the final attempt when no retry remains. This adds one second of unnecessary latency before the client raises its terminal SmithyIdentityError.
With the default three attempts, a terminal failure incurs three one-second sleeps even though only two delays are needed between attempts. With retries=1, the single request still takes about one extra second to fail.
Regression Issue
This does not appear to be a regression.
Expected Behavior
The client should sleep only between attempts. After the final attempt fails, it should raise immediately.
Current Behavior
The except block awaits asyncio.sleep(_SLEEP_SECONDS) before incrementing/checking the attempt count, so the final failure always sleeps before leaving the loop.
Reproduction Steps
import asyncio
from time import monotonic
from aws_credentials_http.client import HttpCredentialsClient
from smithy_core import URI
from smithy_core.exceptions import SmithyIdentityError
from smithy_http import Fields
class FailingClient:
async def send(self, *args, **kwargs):
raise OSError("endpoint unavailable")
async def main():
client = HttpCredentialsClient(FailingClient(), retries=1) # type: ignore[arg-type]
started = monotonic()
try:
await client.get_credentials(
URI(scheme="http", host="169.254.170.2", path="/credentials"),
Fields(),
)
except SmithyIdentityError:
print(f"elapsed: {monotonic() - started:.1f}s")
asyncio.run(main())
On aws-credentials-http==0.3.0, this prints approximately elapsed: 1.0s even though only one request is configured and there is no subsequent retry to wait for.
Possible Solution
Increment the attempt count first, then await the retry delay only when attempts < self._retries. A regression test can mock asyncio.sleep and assert that two attempts produce one sleep.
Additional Information/Context
Confirmed against the current develop branch (5fed4da) and the latest published aws-credentials-http release, 0.3.0.
Affected area
credentials / authentication
Affected package(s)
aws-credentials-http 0.3.0
Python version used
Python 3.14.0
Operating System and version
macOS 27.0.1
- 主要语言
- Python
- 星标
- 173
- 派生
- 23
- 平均合并
- 2 天 7 小时
- 30 天内合并 PR
- 9
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aws/aws-sdk-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
aws/aws-sdk-python#13 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 25/100
aws/aws-sdk-python#99 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
aws/aws-sdk-python#92 ·
维护者通常 1 天内回复
-
announcement
难度 5/5 一周以上 新手友好度 25/100
aws/aws-sdk-python#90 ·
维护者通常 1 天内回复
-
announcement
难度 3/5 1-2 天 新手友好度 35/100
aws/aws-sdk-python#84 ·
维护者通常 1 天内回复