AsyncStream does not close its SSE decoder and byte iterators before releasing the response
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
Start with src/openai/_streaming.py and trace how AsyncStream.__aiter__, _iter_events, close(), and __stream__ manage the decoder, byte iterator, and response. Reproduce the early-break case with the described httpx.AsyncByteStream and MockTransport setup. Done means both inner iterators close before the response when the consumer exits its aclosing block.
由索引模型根據 Issue 內容生成。
描述
Version: openai 3.46.0 (also main as of 2026-11-09), src/openai/_streaming.py
What happens
AsyncStream.__aiter__ is an async generator that delegates to self._iterator, and
_iter_events iterates self._decoder.aiter_bytes(self.response.aiter_bytes()) without closing
either inner iterator. AsyncStream.close() / __stream__'s cleanup call response.aclose()
only. When a consumer stops early, the decoder generator and the byte iterator are left suspended
and are finalized later by the garbage collector, possibly concurrently with other streams, instead
of being closed before the response they read from is released.
Expected
-
__aiter__returnsself(the class already implements__anext__), removing one generator
layer. -
_iter_eventscloses what it opened:body = self.response.aiter_bytes() events = self._decoder.aiter_bytes(body) try: async for sse in events: yield sse finally: try: if isinstance(events, AsyncGenerator): await events.aclose() finally: await body.aclose() -
close()and the end of__stream__close the iterator before the response:try: await self._iterator.aclose() finally: await self.response.aclose()
How we test it: an httpx.AsyncByteStream whose __aiter__ sets a flag in its finally,
served through MockTransport, consumed through a Responses stream with an early break; with
this change the body and its iterator are both closed when the consumer's aclosing block exits.
We run this as a local patch; happy to open a PR.
- 主要語言
- Python
- 星號
- 32.2k
- 分支
- 5.8k
- 平均合併
- 12 小時 29 分鐘
- 30 天內合併 PR
- 112
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
openai/openai-python 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
openai/openai-python#4338 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 65/100
openai/openai-python#4337 ·
維護者通常 1 天內回覆
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parameters可能已有人在做 @Rewaskc02-lang 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
openai/openai-python#4311 · 4 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
openai/openai-python#4310 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
openai/openai-python#4309 · 1 則留言 ·
維護者通常 1 天內回覆
查看 openai/openai-python 的全部 Issue
相似的 Issue
-
triage
難度 1/5 1-3 小時 新手友好度 88/100
kornia/kornia-rs#1416 · 1 則留言 ·
維護者通常 2 天內回覆
-
ui
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
PolicyEngine/ai-inequality#64 ·
維護者通常 1 天內回覆
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over time可能已有人在做 @PabloRoque 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 88/100
pymc-devs/pymc-extras#839 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆