-
Notifications
You must be signed in to change notification settings - Fork 88
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
Keep track of absolute IDLE time for timeout #303
base: main
Are you sure you want to change the base?
Conversation
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.
Thank you for this! Two nits, and then one thing that I think is wrong (but also easily fixed).
src/extensions/idle.rs
Outdated
// re-issue it at least every 29 minutes to avoid being logged off. | ||
// This still allows a client to receive immediate mailbox updates even | ||
// though it need only "poll" at half hour intervals. | ||
let time_since_idle = Instant::now() - self.last_idle.map(Ok).unwrap_or_else(|| self.init())?; |
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.
let time_since_idle = Instant::now() - self.last_idle.map(Ok).unwrap_or_else(|| self.init())?; | |
let time_since_idle = self.last_idle.map(|t| Ok(t.elapsed())).unwrap_or_else(|| self.init())?; |
src/extensions/idle.rs
Outdated
// set_read_timeout() can fail if the argument is Some(0), which can never | ||
// be the case here. | ||
.unwrap(); |
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.
// set_read_timeout() can fail if the argument is Some(0), which can never | |
// be the case here. | |
.unwrap(); | |
.expect("cannot be Some(0) since time is monotonically increasing"); |
src/extensions/idle.rs
Outdated
// re-issue it at least every 29 minutes to avoid being logged off. | ||
// This still allows a client to receive immediate mailbox updates even | ||
// though it need only "poll" at half hour intervals. | ||
let time_since_idle = Instant::now() - self.last_idle.map(Ok).unwrap_or_else(|| self.init())?; |
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.
I think this means that if init
fails, we may fail to reset the read timeout to None
if we've already gone around the loop at least one? Because the ?
here will return from the function, not into the match.
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.
True. Also from self.terminate()?
a couple of lines below. I'll change both to break on Err
instead of using ?
.
src/extensions/idle.rs
Outdated
if self.keepalive { | ||
self.terminate()?; | ||
continue; | ||
} |
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.
Nice — this makes the flow much better.
a94dedb
to
3df945a
Compare
The code used to apply the set timeout value to the TcpStream before entering the IDLE loop. This effectively resets the timeout after receiving and handling incoming messages, which nullifies the purpose of the timeout when messages are received. This change remembers when the IDLE command is sent initially and uses that value to set the remaining time for the TcpStream timeout. This allows the IDLE loop to reconnect the IDLE connection at the appropriate time. Fixes jonhoo#300.
Fixes #300.
This change is