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 天內回覆
-
feature-request p3 queued
難度 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 天內回覆
查看 aws/aws-sdk-python 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 88/100
-
難度 1/5 1 小時以內 新手友好度 92/100
QuantEcon/lecture-python-programming#642 ·
維護者通常 1 天內回覆
-
area/config area/profiles comp/cli needs-decision P3 sweeper:risk-compatibility type/feature
難度 2/5 1-3 小時 新手友好度 82/100
NousResearch/hermes-agent#133697 ·
維護者通常 1 天內回覆
-
enhancement needs-triage
難度 1/5 1 小時以內 新手友好度 72/100
維護者通常 1 天內回覆
-
core
難度 2/5 1-3 小時 新手友好度 88/100
vectorize-io/hindsight#5279 ·
維護者通常 1 天內回覆