Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Container credentials client sleeps after the final failed attempt

未關閉 適合新手
#106 2 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 1 天內回覆

@gauravkriplani 已經在處理了。

開始於 2026年10月3日。

  • #107 來自 @gauravkriplani —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python

研究方向

從 HttpCredentialsClient.get_credentials() 開始,檢查 issue 中描述的例外處理重試迴圈。新增或更新一個回歸測試,對 asyncio.sleep 進行 mock,並驗證兩次嘗試產生一次 sleep,而最終失敗會立即拋出;terminal SmithyIdentityError 應保持不變。

由索引模型根據 Issue 內容生成。

描述

bug p2
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 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

aws/aws-sdk-python 的其他 Issue

查看 aws/aws-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。