Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit c46c6be

Browse files
authored
Produce an error if coverage recording failed due to timeout (#2529)
Closes #2520. After investigation the underlying cause here is that the process is getting killed due to timeout, but we don't report the timeout or produce an error. Modify the coverage code so that it fails if timeout is hit.
1 parent b3fd6d5 commit c46c6be

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/agent/coverage/src/block/linux.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::collections::BTreeMap;
55
use std::convert::TryInto;
66
use std::ffi::OsStr;
77
use std::process::Command;
8-
use std::sync::mpsc;
8+
use std::sync::atomic::{AtomicBool, Ordering};
9+
use std::sync::{mpsc, Arc};
910
use std::thread;
1011
use std::time::{Duration, Instant};
1112

@@ -40,7 +41,7 @@ impl<'c> Recorder<'c> {
4041
let mut tracer = Ptracer::new();
4142
let mut child = tracer.spawn(cmd)?;
4243

43-
let _timer = Timer::new(timeout, move || child.kill());
44+
let timer = Timer::new(timeout, move || child.kill());
4445

4546
let recorder = Recorder {
4647
breakpoints: Breakpoints::default(),
@@ -54,7 +55,14 @@ impl<'c> Recorder<'c> {
5455

5556
let coverage = recorder.wait()?;
5657

57-
Ok(coverage)
58+
if timer.timed_out() {
59+
Err(anyhow::format_err!(
60+
"timed out creating recording after {}s",
61+
timeout.as_secs_f64()
62+
))
63+
} else {
64+
Ok(coverage)
65+
}
5866
}
5967

6068
fn wait(mut self) -> Result<CommandBlockCov> {
@@ -429,6 +437,7 @@ const MAX_POLL_PERIOD: Duration = Duration::from_millis(500);
429437

430438
pub struct Timer {
431439
sender: mpsc::Sender<()>,
440+
timed_out: Arc<AtomicBool>,
432441
_handle: thread::JoinHandle<()>,
433442
}
434443

@@ -438,7 +447,9 @@ impl Timer {
438447
F: FnOnce() -> T + Send + 'static,
439448
{
440449
let (sender, receiver) = std::sync::mpsc::channel();
450+
let timed_out = Arc::new(AtomicBool::new(false));
441451

452+
let set_timed_out = timed_out.clone();
442453
let _handle = thread::spawn(move || {
443454
let poll_period = Duration::min(timeout, MAX_POLL_PERIOD);
444455
let start = Instant::now();
@@ -455,11 +466,20 @@ impl Timer {
455466
}
456467
}
457468

469+
set_timed_out.store(true, Ordering::SeqCst);
458470
// Timed out, so call back.
459471
on_timeout();
460472
});
461473

462-
Self { sender, _handle }
474+
Self {
475+
sender,
476+
_handle,
477+
timed_out,
478+
}
479+
}
480+
481+
pub fn timed_out(&self) -> bool {
482+
self.timed_out.load(Ordering::SeqCst)
463483
}
464484

465485
pub fn cancel(self) {

0 commit comments

Comments
 (0)