Skip to content

[cronet_http] StreamedResponse does not close after cancelling the response stream #1757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Colton127 opened this issue Apr 25, 2025 · 1 comment · Fixed by #1760
Closed
Assignees
Labels
package:cronet_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@Colton127
Copy link

In cronet_http, cancelling the stream on a StreamedResponse does not close the underlying connection.

final engine = CronetEngine.build(cacheMode: CacheMode.disabled);
final client = CronetClient.fromCronetEngine(engine, closeEngine: true);
final request = Request('GET', Uri.parse('https://cachefly.cachefly.net/100mb.test'));
final streamedResponse = await client.send(request);
final streamSubscription = streamedResponse.stream.listen(null);
await Future.delayed(const Duration(seconds: 5));
await streamSubscription.cancel();

Despite the stream subscription being cancelled, the connection continues to remain active until the full body is received:

Image

In contrast, the standard IOClient closes the connection when the stream subscription is cancelled. Notice the "Timespan":

Image

@Colton127 Colton127 added package:cronet_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Apr 25, 2025
@Colton127 Colton127 changed the title StreamedResponse does not close after cancelling the response stream [cronet_http] StreamedResponse does not close after cancelling the response stream Apr 25, 2025
@brianquinlan
Copy link
Collaborator

Ah, that's interesting. Probably the StreamController i.e. https://github.com/dart-lang/http/blob/63c477b466f650e8f5505d6d78dc283c2c2f9845/pkgs/cronet_http/lib/src/cronet_client.dart#L162C24-L162C40

should handle onCancel and call UrlRequest.cancel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:cronet_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
2 participants