Fix LineIterator hanging forever when the stream ends without a trailing newline - #6279
Open
RudraDudhat2509 wants to merge 1 commit into
Open
RudraDudhat2509 wants to merge 1 commit into
RudraDudhat2509 wants to merge 1 commit into
Conversation
…ing newline When the underlying event stream is exhausted (StopIteration) while the buffer still has an unread trailing partial line (no "\n" at the end, a normal case since the model's last streamed token has no reason to be a newline), __next__ just did `continue`. That re-reads the exact same unterminated line, fails the same check, and calls next() on an already-exhausted iterator again, forever. Nothing in that branch ever changes state, so it spins indefinitely instead of returning or raising. Return the leftover partial data once instead, so the following call correctly hits the read_pos == buffer size case and raises StopIteration normally. Added test_line_iterator_no_trailing_newline_at_end since the existing test_line_iterator_incomplete_line_at_end doesn't actually cover this, it only tests a stream that ends cleanly with a trailing newline.
RudraDudhat2509
requested a deployment
to
manual-approval
September 15, 2026 17:48 — with
GitHub Actions
Waiting
RudraDudhat2509
requested a deployment
to
manual-approval
September 15, 2026 17:48 — with
GitHub Actions
Waiting
RudraDudhat2509
requested a deployment
to
manual-approval
September 15, 2026 17:48 — with
GitHub Actions
Waiting
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.
Fixes #6278
Returns the leftover partial line once instead of
continue, so the next call correctly hitsread_pos == buffer sizeand raisesStopIterationnormally instead of looping forever.Added
test_line_iterator_no_trailing_newline_at_end.test_line_iterator_incomplete_line_at_enddoesn't actually cover this, it only tests a stream that already ends with\n.Verified against the pre-fix code: hangs, confirmed by killing it after 15s with no output. Full
test_iterators.py21 passed after the fix.