Repository navigation
Fix LineIterator hanging forever when the stream ends without a trailing newline - #6279
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.
|
Gentle ping |
|
Claude finished @rsareddy0329's task in 47s —— View job Code Review
I reviewed the change to CorrectnessThe root cause is accurately diagnosed. In
The fix returns the remainder once and advances Returning the unterminated remainder (rather than dropping it) is the right call — it surfaces the final bytes to the consumer instead of silently discarding data, and it's consistent with the normal path since there is no Tests
Minor observation (non-blocking)At No security, performance, or backward-compatibility concerns. This is a solid bug fix. |
|
@rsareddy0329 thanks for kicking off the review. happy to fix the non blocking issue that claude pointed out, also the ci fails are unrelated to the files staged, thx again |
PR changes looks good and approving as claude recommendation is non-blocking. |
|
Appreciate the quick review cycle thanks !🚀 |
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.