-
Notifications
You must be signed in to change notification settings - Fork 362
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
Request cancellation/abort through cancellation-token #602
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@FaFre - did you have a chance to check out the CLA agreement linked above? |
@natebosch - haven't had the time to read the agreement yet. Will do it today or tomorrow. |
@googlebot I signed it! |
@FaFre Thank you very much for this Draft and PR |
@aytunch I'm happy you find use in it 👍 You need to check that on your own with an package sniffer on each platform you want to provide your app for (unless somebody did already research on that...). I'm not familiar with Firebase storage but I assume you just have an basic HTTP-Download. In that case it should be enough to close the TCP connection to stop the download. And this is what you need to confirm with an package sniffer. |
I understand @FaFre thanks |
@aytunch However, the implementation for web may need some further investigation. Although I implemented it like in the documentation described, my requests didn't get cancelled accordingly. I couldn't fix that on my own so far, but it's also possible that this effect is caused by the dart libraries and I do everything correctly here. |
@aytunch While doing some research on the web request I actually discovered that also the dart:io implementation isn't able to abort requests once the server started sending data. The implementation seems to see a request as done once the server starts sending data. Therefore they cannot get aborted anymore. final bigFileUrl = Uri.https('ftp5.gwdg.de',
'/pub/misc/openstreetmap/planet.openstreetmap.org/pbf/planet-latest.osm.pbf'); //~60GB file
final req = await HttpClient().getUrl(bigFileUrl);
unawaited(Future.delayed(const Duration(seconds: 1)).whenComplete(() {
req.abort();
print('sent abort');
}));
final resp = await req.close();
print(await resp.toList()); The code above confirms with DevTools that the HTTP request is still running and memory is filling up. @natebosch I saw you also did some research on abort() and opened some issues regarding it. Is this behavior already discussed somewhere? |
I think once we have a response, instead of I do have plans to revisit timeouts and request aborting soon. I suspect we won't be able to use this PR because it would be a breaking change that might be too hard to roll out, but I have not yet finished exploring the implications of various designs. |
I've been working on a fork with cancellation using a CancellationToken, but I've taken a different approach with the tokens so they're not specific to HTTP requests: https://github.com/JonathanPeterCole/dart-cancellation-token-http |
Closing this, as it is stale and the files are out of date. Feel free to reopen in case you still want to land it! |
This is an effort trying to tackle the problems discussed in #567, #424, and #204.
This solution introduces a
CancellationToken
, which is passed into the http-methods ofClient
e.g.:This design is avoiding breaking changes.
Despite most cancellation-token-based solutions (working with a simple
Completer
), this approach is also trying to reallyabort()
a request if necessary.It is possible to add multiple requests to a
CancellationToken
, to cancel them at once when triggered (disposal of the token has to get done manually in that case).A request can (if requested) get aborted at multiple points:
CancellationToken
Stream
-based invoke ofabort()
Status:
Cancellation is supported and implemented for both
IOClient
andBrowserClient
.Existing tests have been fixed, but no new tests written yet.
It will need some further reviews.
Problems:
The
abort()
onHttpRequest
(for web) doesn't seem to have any effect during my tests (request time < 800ms) - although it's called during the accordingreadyState
(https://api.flutter.dev/flutter/dart-html/HttpRequest/abort.html)