auth: AsyncAuthorizedSession.request leaks response across retry attempts
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 88/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
- 领域
- networking
调研方向
从 packages/google-auth/google/auth/aio/transport/sessions.py 中的 AsyncAuthorizedSession.request 开始,然后将其重试循环与第 501-518 行的清理模式进行比较。为可重试的 503 后跟 200 添加单元测试覆盖,验证在继续重试之前已等待初始响应的 close()。
由索引模型根据 Issue 内容生成。
描述
In google.auth.aio.transport.sessions.AsyncAuthorizedSession.request (packages/google-auth/google/auth/aio/transport/sessions.py:339-347), the retry loop reassigns response = await with_timeout(...) across retry attempts without closing the previous response.
If the response payload hasn't reached EOF before the next retry fires (e.g., with chunked or streaming responses), aiohttp keeps the socket checked out in connector._acquired. The transport protocol's internal EOF callback holds a bound reference to ClientResponse._response_eof, which prevents Python's garbage collector from cleaning up the orphaned response while the connection is waiting for data. Under concurrency, multiple requests retrying against a degraded endpoint can quickly burn through the connector pool (limit=100) and block other outgoing requests across the session.
Proposed Fix
Close any previous response before kicking off the next retry attempt, matching the pattern already used in sessions.py:L501-L518:
response = None
async for _ in retries:
if response is not None and hasattr(response, "close"):
try:
res = response.close()
if inspect.isawaitable(res):
await res
except Exception:
pass
response = await with_timeout(
self._auth_request(
url, method, data, request_headers, actual_timeout, **kwargs
)
)
if response.status_code not in transport.DEFAULT_RETRYABLE_STATUS_CODES:
break
Unit tests should check that when a retryable status code (like a 503) is followed by a 200, close() is awaited on the initial response before the retry runs.
- 主要语言
- Python
- 星标
- 5.4k
- 派生
- 1.8k
- 平均合并
- 1 天 17 小时
- 30 天内合并 PR
- 93
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleapis/google-cloud-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
googleapis/google-cloud-python#18428 ·
-
priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 72/100
googleapis/google-cloud-python#18375 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 76/100
googleapis/google-cloud-python#18339 ·
-
priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 78/100
googleapis/google-cloud-python#18260 ·
-
auth effort: low priority: p4 testing type: cleanup
难度 2/5 1-3 小时 新手友好度 85/100
googleapis/google-cloud-python#17760 ·
查看 googleapis/google-cloud-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
enhancement
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 74/100