Async streaming response wrappers leak an unawaited coroutine when not entered

未关闭 适合新手
#175 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
python
领域
api

调研方向

从 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-685
  • AsyncResponseContextManager stores an already-created Awaitable at src/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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

browserbase/sdk-python 的其他 Issue

查看 browserbase/sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。