-
Notifications
You must be signed in to change notification settings - Fork 125
Task
doesn't correctly reference follow-on RequestBag objects so it cannot cancel them after redirect.
#753
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
Comments
Follow up: canceling the |
Sorry for this sitting unanswered over the weekend @gregcotten, let me see if I can reproduce this. |
Ok, so I don't reproduce this locally with a simple alternative. Here's the complete code I'm running:
This code correctly throws at the top level, showing the following output in the console:
You appear to be using slightly different APIs though, I can't find the APIs you're using on AHC. Do you know where they're coming from? If you run my sample code, do you see the same output as me? |
Downloading from a real-world location and trying to cancel from the vended
Essentially after If you need a link to a semi-large file, this might suffice:
|
@Lukasa here's a reproducible test case: Just run |
Huh, so this is interesting. The problem isn't the download, it's the redirect. The test as-written gets a 301, which can be seen in the log output:
If we rewrite the test to avoid the 301 (by changing the URL to
So I think the actual problem we have here is the task cancellation not working after a redirect is followed. |
Task
doesn't actually cancel it?Task
doesn't correctly reference follow-on RequestBag objects so it cannot cancel them after redirect.
I've updated the title here, because I think this is the crux of the issue. On a HTTP redirect, a new This turns out not to matter beyond cancellation. The underlying response promise is forwarded on, so only cancellation fails to work. There are a number of possible fixes, but the easiest one is to have the |
Resolved by #814. |
Uh oh!
There was an error while loading. Please reload this page.
Update
Reproducible test case:
https://github.com/gregcotten/ahc-download-cancel-bug
Just run
swift test
It turns out that a redirect causes a new task to be created, so you can't count on execute(...)'s Task to be the only Task you'll need to cancel. I'll put a workaround on the above repo at some point.
Original
Stubbing this for now with hope to provide a reproducible test case when I have time...
I'm hoping to use structured concurrency Task cancellation to actually cancel a download, so I did something like this:
The actual download progresses until it's done downloading the file, no matter what, and then
downloadTask.get()
returns without throwing an error.What am I doing wrong here?
The text was updated successfully, but these errors were encountered: