Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

z33ky
Copy link

@z33ky z33ky commented Jan 28, 2025

Fixes #300.


This change is Reviewable

Copy link
Owner

@jonhoo jonhoo left a 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).

// 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())?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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())?;

Comment on lines 178 to 180
// set_read_timeout() can fail if the argument is Some(0), which can never
// be the case here.
.unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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");

// 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())?;
Copy link
Owner

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.

Copy link
Author

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 ?.

Comment on lines 188 to 203
if self.keepalive {
self.terminate()?;
continue;
}
Copy link
Owner

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.

@z33ky z33ky force-pushed the abs-idle-timeout branch 3 times, most recently from a94dedb to 3df945a Compare February 16, 2025 10:46
@z33ky z33ky requested a review from jonhoo March 25, 2025 22:58
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.
@z33ky z33ky force-pushed the abs-idle-timeout branch from 3df945a to bab6789 Compare March 25, 2025 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrongful IDLE timeout reset on response
2 participants