AsyncStream does not close its SSE decoder and byte iterators before releasing the response
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 32.2k
- Fork
- 5.8k
- Merge medio
- 12h 29m
- PR unite (30g)
- 112
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di openai/openai-python
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
openai/openai-python#4338 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
openai/openai-python#4337 ·
I maintainer di solito rispondono entro 1 giorno
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parametersForse già presa @Rewaskc02-lang l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
openai/openai-python#4311 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
openai/openai-python#4310 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
openai/openai-python#4309 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di openai/openai-python
Issue simili
-
triage
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
kornia/kornia-rs#1416 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
PolicyEngine/ai-inequality#64 ·
I maintainer di solito rispondono entro 1 giorno
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over timeForse già presa @PabloRoque l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
pymc-devs/pymc-extras#839 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno