Skip to content

Commit

Permalink
fix: do not panic on TestOutputPipe::flush when receiver dropped (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed May 10, 2022
1 parent 75f373d commit e3f4b02
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cli/tools/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1622,13 +1622,16 @@ impl TestOutputPipe {
// We want to wake up the other thread and have it respond back
// that it's done clearing out its pipe before returning.
let (sender, receiver) = std::sync::mpsc::channel();
self.state.lock().replace(sender);
if let Some(sender) = self.state.lock().replace(sender) {
let _ = sender.send(()); // just in case
}
// Bit of a hack to send a zero width space in order to wake
// the thread up. It seems that sending zero bytes here does
// not work on windows.
self.writer.write_all(ZERO_WIDTH_SPACE.as_bytes()).unwrap();
self.writer.flush().unwrap();
receiver.recv().unwrap();
// ignore the error as it might have been picked up and closed
let _ = receiver.recv();
}

pub fn as_file(&self) -> std::fs::File {
Expand Down

0 comments on commit e3f4b02

Please sign in to comment.