Async streaming response wrappers leak an unawaited coroutine when not entered
还没有人认领这个 Issue。
评估
调研方向
从 src/browserbase/_response.py:632-637 和 669-685 开始,对比 AsyncResponseContextManager 与同步的 ResponseContextManager。重现 issue 中丢弃 manager 但未进入该 manager 的情况,然后添加一个生命周期测试,证明不会发出未 await 协程的警告,并且进入 manager 仍会执行预期的请求。
由索引模型根据 Issue 内容生成。
描述
Description
The async .with_streaming_response wrappers create the endpoint coroutine immediately, before the returned context manager is entered. If the context manager is conditionally discarded or never entered, Python emits RuntimeWarning: coroutine ... was never awaited.
This differs from the synchronous wrapper, which stores a callable and does not invoke the endpoint until __enter__.
Code reference
src/browserbase/_response.py:669-685AsyncResponseContextManagerstores an already-createdAwaitableatsrc/browserbase/_response.py:632-637
Reproduction
import asyncio
import gc
import warnings
from browserbase import AsyncBrowserbase
async def main():
client = AsyncBrowserbase(api_key="test")
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
cm = client.sessions.with_streaming_response.create(project_id="p")
del cm
gc.collect()
await asyncio.sleep(0)
print([str(w.message) for w in caught])
await client.close()
asyncio.run(main())
Actual output includes:
coroutine 'AsyncSessionsResource.create' was never awaited
No HTTP request is needed to reproduce this.
Expected behavior
Creating and discarding an unentered response context manager should not allocate an unawaited coroutine or emit a resource warning. The async manager could retain a callable/partial and invoke it lazily from __aenter__, matching ResponseContextManager.
Why it matters
Warnings are promoted to errors in many test suites, and conditional streaming code can produce noisy, nondeterministic resource warnings. This path currently has no direct lifecycle test.
- 主要语言
- Python
- 星标
- 93
- 派生
- 16
- 平均合并
- 11 分钟
- 30 天内合并 PR
- 3
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
browserbase/sdk-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
browserbase/sdk-python#182 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
browserbase/sdk-python#180 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
browserbase/sdk-python#179 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
browserbase/sdk-python#178 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
browserbase/sdk-python#176 ·
查看 browserbase/sdk-python 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 88/100
use-agent-os/agent-os#3314 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
BasedHardware/omi#15662 · 1 条评论 ·
-
documentation help wanted
难度 2/5 1-3 小时 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 62/100
AiursoftWeb/AnduinOS-2#19 ·