-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle interrupts while polling #164
Conversation
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, if `ErrorKind::Interrupted` is received by the underlying `wait()` call, it clears the events and tries to wait again. This also adds a test for this interruption written by @psychon. Co-Authored-By: Uli Schlachter <[email protected]> Signed-off-by: John Nunley <[email protected]>
Signed-off-by: John Nunley <[email protected]>
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):
I 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(timeout concerns)
Signed-off-by: John Nunley <[email protected]>
Signed-off-by: John Nunley <[email protected]>
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