Skip to content
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

Make the fetch target non-optional. #14465

Merged
merged 9 commits into from Dec 15, 2016
Next

Avoid unlocking the response body while it is in an inconsistent state.

  • Loading branch information
Ms2ger committed Dec 15, 2016
commit 8a4a5c0cb515242823289691a67fc553244eaa2e
@@ -42,7 +42,7 @@ use std::collections::HashSet;
use std::error::Error;
use std::io::{self, Read, Write};
use std::iter::FromIterator;
use std::mem::swap;
use std::mem;
use std::ops::Deref;
use std::rc::Rc;
use std::sync::{Arc, RwLock};
@@ -1101,16 +1101,14 @@ fn http_network_fetch(request: Rc<Request>,
}
},
Ok(Data::Done) | Err(_) => {
let mut empty_vec = Vec::new();
let completed_body = match *res_body.lock().unwrap() {
let mut body = res_body.lock().unwrap();
let completed_body = match *body {
ResponseBody::Receiving(ref mut body) => {
// avoid cloning the body
swap(body, &mut empty_vec);
empty_vec
mem::replace(body, vec![])
},
_ => empty_vec,
_ => vec![],
};
*res_body.lock().unwrap() = ResponseBody::Done(completed_body);
*body = ResponseBody::Done(completed_body);
let _ = done_sender.send(Data::Done);
break;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.