fix: consume stream to prevent hanging#260
Merged
gradenr merged 2 commits intoDec 4, 2025
Merged
Conversation
Collaborator
|
This issue has been in the code generator. |
gradenr
approved these changes
Dec 4, 2025
Merged
| yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response) | ||
| # The stream needs to be fully consumed to close the response | ||
| for _sse in iterator: | ||
| ... |
There was a problem hiding this comment.
Bug: Stream not consumed when exception occurs during streaming
The removal of the try-finally block creates a bug where the stream-consuming code at the end of __stream__ (lines 98-100 for sync, 199-201 for async) is never reached if an APIError is raised during iteration. When an error SSE is received and APIError is raised, the exception propagates immediately without consuming the remaining stream, which could cause the same hanging issue this PR attempts to fix. The stream consumption logic needs to be wrapped in a try-finally to ensure it executes even when exceptions occur.
Additional Locations (1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit changed how the stream was closed, and means that clients can end up hanging after calling the stream.
Note
Ensure sync/async streaming drains remaining SSE events after [DONE] so the HTTP response closes without hanging.
Stream.__stream__andAsyncStream.__stream__insrc/groq/_streaming.py:try/finallyimmediate response close; instead drain the SSE iterator after encountering[DONE]to trigger connection closure.errorevents.Written by Cursor Bugbot for commit 8ac6a76. This will update automatically on new commits. Configure here.