fix(python): raise on mid-stream body errors instead of silent EOF#482
Open
barjin wants to merge 1 commit into
Open
fix(python): raise on mid-stream body errors instead of silent EOF#482barjin wants to merge 1 commit into
barjin wants to merge 1 commit into
Conversation
A mid-stream body error (connection reset, truncated chunked transfer) was mapped to StopIteration/StopAsyncIteration, which signals normal end of iteration. The `async for`/`for` loop ended silently and the caller processed a partial body believing it was complete - a silent data-integrity bug. Now the classified ImpitError is propagated as a real exception, and the consumed/closed flags are set consistently with the clean-EOF branch. Streamed body truncation surfaces in reqwest as a `Decode`-kinded error rather than `Body`, so the existing unexpected-EOF classification missed it and fell through to the catch-all HTTPError. Widen the guard to cover `is_decode()` so truncated streams are reported as RemoteProtocolError, matching httpx.
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.
Mid-stream body errors (connection reset, truncated chunked transfer) were mapped to
StopIteration/StopAsyncIteration, which signal normal end-of-iteration — sofor/async forended silently and callers processed partial bodies as complete (a silent data-integrity bug, #475). Both sync and async iterators now propagate the classifiedImpitErroras a real exception and set the consumed/closed flags consistently with the clean-EOF branch.Streamed truncation surfaces in reqwest as a
Decode-kinded error rather thanBody, so the existing unexpected-EOF classification missed it and fell through to the catch-allHTTPError. The guard is widened to coveris_decode(), so truncated streams now raiseRemoteProtocolError, matching httpx.Verified against a vanilla server that truncates the body mid-response; added sync + async regression tests.
Closes #475