-
Notifications
You must be signed in to change notification settings - Fork 643
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
Rework session keep-alive logic #1357
Conversation
Updated to implement a modified timeout handling:
Unfortunately, this has turned the code quite a bit more complicated. What do you think? Is this overkill? Any suggestion on improving (simplifying) it? |
First of all, thanks a lot for this. I'm thrilled to see the recent influx of good contributions here. v0.5 is shaping up to be a solid release, getting these last issues ironed out like this!
My take: correctness goes first. Then, making the code as simple as can be - maintaining correctness. So principally I don't mind more complex code if that's what it takes. But, indeed, maybe a counter-suggestion that I've applied elsewhere, if it fits this use-case also: Have two watchdogs: watchdog_rx: Pin<Box<tokio::time::Sleep>>,
watchdog_tx: Pin<Box<tokio::time::Sleep>>, Polling it: self.watchdog_tx = tokio::time::sleep(PONG_TIMEOUT);
self.watchdog_rx = tokio::time::sleep(PING_TIMEOUT);
tokio::select! {
() = &mut self.watchdog_tx, if self.ping_received => {
self.send_pong().await
}
() = &mut self.watchdog_rx => {
// connection to server timed out
}
} And something like: fn handle_ping(&mut self) {
self.ping_received = true;
}
fn send_pong(&mut self) {
self.ping_received = false;
// send the pong, then reset the timer
self.watchdog_tx = tokio::time::sleep(PONG_TIMEOUT);
}
fn handle_pong_ack(&mut self) {
self.watchdog_rx = tokio::time::sleep(PING_TIMEOUT);
} |
Hmm, I don't see how this would work out in this case: With the current design, the It might be possible to implement your design by moving the watchdog task from the Am I missing something here? |
Closing in favor of #1359. |
Tentative fix for #1340. Also add some logging to show the timing (at info level for now, so we're sure that it's available from everyone who tests it).