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
Fetch cancellation #19274
Merged
+98
−31
Merged
Fetch cancellation #19274
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1dfb125
Fetch cancellation: Add cancel_chan to FetchContext
Manishearth 87e4c15
Fetch cancellation: Store cancel_chan in XHR
Manishearth 27457e4
Fetch cancellation: Send cancellation message whenever XHR needs to a…
Manishearth 6dd7af2
Fetch cancellation: Add CancellationListener
Manishearth 7249fd6
Fetch cancellation: Listen for cancellation and prematurely abort if …
Manishearth 6f59b15
Add aborted flag to response, set when fetch is aborted
Manishearth File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Fetch cancellation: Listen for cancellation and prematurely abort if …
…cancelled
- Loading branch information
commit 7249fd6bd82b70fa097ce2c66dc8bdb4bf023da8
| @@ -1087,6 +1087,7 @@ fn http_network_fetch(request: &Request, | ||
| let devtools_sender = context.devtools_chan.clone(); | ||
| let meta_status = meta.status.clone(); | ||
| let meta_headers = meta.headers.clone(); | ||
| let cancellation_listener = context.cancellation_listener.clone(); | ||
| thread::Builder::new().name(format!("fetch worker thread")).spawn(move || { | ||
| match StreamedResponse::from_http_response(res) { | ||
| Ok(mut res) => { | ||
| @@ -1109,6 +1110,11 @@ fn http_network_fetch(request: &Request, | ||
| } | ||
|
|
||
| loop { | ||
| if cancellation_listener.lock().unwrap().cancelled() { | ||
| *res_body.lock().unwrap() = ResponseBody::Done(vec![]); | ||
gterzian
Member
|
||
| let _ = done_sender.send(Data::Done); | ||
| return; | ||
| } | ||
| match read_block(&mut res) { | ||
| Ok(Data::Payload(chunk)) => { | ||
| if let ResponseBody::Receiving(ref mut body) = *res_body.lock().unwrap() { | ||
ProTip!
Use n and p to navigate between commits in a pull request.
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.
In the context of #18676 I think that at this point the response would have been cached already, and such a cancellation would result in any subsequent request for the same url getting the empty cancelled response from the cache.
One way to solve this would be for the cache to disregard any cached responses that would have been cancelled. Checking for an empty response body might be one way to do so, perhaps a clearer way would be to use
ResponseBody::Emptyhere instead, or even introduce a newResponseBody::Cancelled?