Skip to content

Commit adedee1

Browse files
committed
Fix signal timeout handling when accept_sigusr is disabled
A different implementation of the fix proposed in #53. Thanks @phlip9!
1 parent 552132a commit adedee1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/signal.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crossbeam_channel as channel;
22
use crossbeam_channel::RecvTimeoutError;
33
use std::thread;
4-
use std::time::Duration;
4+
use std::time::{Duration, Instant};
55

66
use signal_hook::consts::{SIGINT, SIGTERM, SIGUSR1};
77

@@ -34,14 +34,21 @@ impl Waiter {
3434
]),
3535
}
3636
}
37+
3738
pub fn wait(&self, duration: Duration, accept_sigusr: bool) -> Result<()> {
38-
match self.receiver.recv_timeout(duration) {
39+
// Determine the deadline time based on the duration, so that it doesn't
40+
// get pushed back when wait_deadline() recurses
41+
self.wait_deadline(Instant::now() + duration, accept_sigusr)
42+
}
43+
44+
fn wait_deadline(&self, deadline: Instant, accept_sigusr: bool) -> Result<()> {
45+
match self.receiver.recv_deadline(deadline) {
3946
Ok(sig) if sig == SIGUSR1 => {
4047
trace!("notified via SIGUSR1");
4148
if accept_sigusr {
4249
Ok(())
4350
} else {
44-
self.wait(duration, accept_sigusr)
51+
self.wait_deadline(deadline, accept_sigusr)
4552
}
4653
}
4754
Ok(sig) => bail!(ErrorKind::Interrupt(sig)),

0 commit comments

Comments
 (0)