AsyncStream does not close its SSE decoder and byte iterators before releasing the response
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 32.2k
- Fork
- 5.8k
- Merge trung bình
- 12 giờ 29 phút
- Pull request đã merge (30 ngày)
- 112
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openai/openai-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
openai/openai-python#4338 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
openai/openai-python#4337 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parametersCó thể đã có người làm @Rewaskc02-lang đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openai/openai-python#4311 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openai/openai-python#4310 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
openai/openai-python#4309 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openai/openai-python
Issue tương tự
-
triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
kornia/kornia-rs#1416 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
PolicyEngine/ai-inequality#64 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over timeCó thể đã có người làm @PabloRoque đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
pymc-devs/pymc-extras#839 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày