Skip to content

Commit

Permalink
Fix a very minor race condition in cargo fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jan 3, 2019
1 parent 21fe000 commit 7584dce
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/cargo/util/diagnostic_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,23 @@ impl RustfixDiagnosticServer {

fn run(self, on_message: &dyn Fn(Message), done: &AtomicBool) {
while let Ok((client, _)) = self.listener.accept() {
let client = BufReader::new(client);
match serde_json::from_reader(client) {
Ok(message) => on_message(message),
Err(e) => warn!("invalid diagnostics message: {}", e),
}
if done.load(Ordering::SeqCst) {
break;
}
let mut client = BufReader::new(client);
let mut s = String::new();
if let Err(e) = client.read_to_string(&mut s) {
warn!("diagnostic server failed to read: {}", e);
} else {
match serde_json::from_str(&s) {
Ok(message) => on_message(message),
Err(e) => warn!("invalid diagnostics message: {}", e),
}
}
// The client should be kept alive until after `on_message` is
// called to ensure that the client doesn't exit too soon (and
// Message::Finish getting posted before Message::FixDiagnostic).
drop(client);
}
}
}
Expand Down

0 comments on commit 7584dce

Please sign in to comment.