Skip to content

fix(python): raise on mid-stream body errors instead of silent EOF#482

Open
barjin wants to merge 1 commit into
masterfrom
fix/python-stream-error-propagation
Open

fix(python): raise on mid-stream body errors instead of silent EOF#482
barjin wants to merge 1 commit into
masterfrom
fix/python-stream-error-propagation

Conversation

@barjin

@barjin barjin commented Jun 12, 2026

Copy link
Copy Markdown
Member

Mid-stream body errors (connection reset, truncated chunked transfer) were mapped to StopIteration/StopAsyncIteration, which signal normal end-of-iteration — so for/async for ended silently and callers processed partial bodies as complete (a silent data-integrity bug, #475). Both sync and async iterators now propagate the classified ImpitError as 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 than Body, so the existing unexpected-EOF classification missed it and fell through to the catch-all HTTPError. The guard is widened to cover is_decode(), so truncated streams now raise RemoteProtocolError, matching httpx.

Verified against a vanilla server that truncates the body mid-response; added sync + async regression tests.

Closes #475

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.
@github-actions github-actions Bot added this to the 142nd sprint - Tooling team milestone Jun 12, 2026
@github-actions github-actions Bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(py) Mid-stream body error raises StopAsyncIteration, so truncated streams look like clean EOF

2 participants