From 209232befd970cad384543b540f0624b2f3e9c2f Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Sat, 5 May 2018 18:55:30 +0200 Subject: [PATCH] signal: Ensure that the driver dies once the signal does `tokio::run` expects that all futures finish processing so we can't leave `Driver` around forever or `tokio::run` would never return. --- src/unix.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/unix.rs b/src/unix.rs index df5c17e37..2cb6d0d8e 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -328,6 +328,7 @@ impl Driver { /// repo, though, as I'd love to chat about this! In other words, I'd love to /// alleviate some of these limitations if possible! pub struct Signal { + driver: Driver, signal: c_int, // Used only as an identifier. We place the real sender into a Box, so it // stays on the same address forever. That gives us a unique pointer, so we @@ -370,7 +371,7 @@ impl Signal { // Ensure there's a driver for our associated event loop processing // signals. - ::tokio_executor::spawn(try!(Driver::new(&handle))); + let driver = try!(Driver::new(&handle)); // One wakeup in a queue is enough, no need for us to buffer up any // more. @@ -380,6 +381,7 @@ impl Signal { let idx = signal as usize; globals().signals[idx].recipients.lock().unwrap().push(tx); Ok(Signal { + driver: driver, rx: rx, id: id, signal: signal, @@ -395,6 +397,7 @@ impl Stream for Signal { type Error = io::Error; fn poll(&mut self) -> Poll, io::Error> { + self.driver.poll().unwrap(); // receivers don't generate errors self.rx.poll().map_err(|_| panic!()) }