fix: keep the request future in the stream pipeline for ResponseType.stream - #921
Merged
trevorwang merged 1 commit intoJul 21, 2026
Conversation
…stream Closes trevorwang#907. Generated methods for @DioResponseType(ResponseType.stream) awaited the request future inside an async* body, so if the subscription was cancelled while suspended at the await, a later error from that future could escape the stream listener lifecycle and surface as an unhandled zone error. Emit _dio.fetch<ResponseBody>(...) without await and expand it through asStream().asyncExpand(...) instead, keeping the future inside the stream.
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.
Closes #907.
The problem
Generated methods for
@DioResponseType(ResponseType.stream)awaited therequest future inside an
async*body:If the stream subscription is cancelled while execution is suspended at that
await, a later error from the pending future is no longer delivered throughthe stream listener lifecycle and can surface as an unhandled zone error. In
practice that shows up as noisy false positives in global error collectors, even
when the consumer is handling stream errors correctly.
The fix
Emit the fetch without
awaitand expand it through the stream pipeline, so thefuture stays inside the stream:
Stream<String>gets the same shape with.map(utf8.decode)inside the expand.This is the change proposed in the issue.
Tests
Updated the two
ResponseType.streamcodegen expectations, forStream<Uint8List>and forStream<String>, to the new generated output.Generator suite green (202 tests),
dart analyzeclean, formatted.