Async streaming response wrappers leak an unawaited coroutine when not entered
まだ誰も着手していません。
評価
調査の方向性
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分
- マージ済み PR(30日)
- 3
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
-
sponsored
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
Diaoul/subliminal#1382 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
triage/confirmed
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
agentscope-ai/agentscope#2775 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100