Closed notgull closed 1 year ago
I would claim that this mis-handles timeouts. A poll with a timeout of one second can now run infinitely long (although this is quite unlikely):
self.poller.wait(events, OneSecond)
runs for 0.5 secondsself.poller.wait(events, OneSecond)
runs for 0.5 secondsI would propose:
diff --git a/src/lib.rs b/src/lib.rs
index 9882c8e..8078ee1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -652,7 +652,14 @@ impl Poller {
if let Ok(_lock) = self.lock.try_lock() {
// Wait for I/O events.
- self.poller.wait(&mut events.events, timeout)?;
+ match self.poller.wait(&mut events.events, timeout) {
+ Ok(()) => {}
+ // Turn interruption into a spurious wakeup without errors
+ Err(e) if e.kind() == io::ErrorKind::Interrupted => {
+ events.clear();
+ },
+ Err(e) => return Err(e),
+ };
// Clear the notification, if any.
self.notified.swap(false, Ordering::SeqCst);
An alternative would be to only do this if no timeout was given (because spurious/non-action wakeups need to be handled anyways when using timeouts usually)
Previous,
Poller::wait
would bubble signal interruption error to the user. However, this may be unexpected for simple use cases. Thus, this commit makes it so, ifErrorKind::Interrupted
is received by the underlyingwait()
call, it clears the events and tries to wait again.This also adds a test for this interruption written by @psychon.
Closes #162