-
Notifications
You must be signed in to change notification settings - Fork 66
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
Implement heartbeat functionality #224
Conversation
Codecov Report
@@ Coverage Diff @@
## master #224 +/- ##
==========================================
- Coverage 97.49% 97.45% -0.04%
==========================================
Files 25 25
Lines 2357 2439 +82
==========================================
+ Hits 2298 2377 +79
- Misses 59 62 +3
Continue to review full report at Codecov.
|
If I understand the codecov report correctly, everything except for errors that can be returned from |
src/config.rs
Outdated
@@ -52,6 +54,7 @@ impl Default for Config { | |||
Self { | |||
blocking_mode: false, | |||
idle_connection_timeout: Duration::from_secs(5), | |||
heartbeat_interval: Duration::from_secs(2), |
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 we should probably, in the future, have this calculated based on the current network circumstances. With two seconds this is safe, we might as well move it up to 3, because the idling time is 5 seconds, then the heartbeat has a total time of 2 seconds to arrive at the client.
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.
Yes, I thought about that as well, but didn't want to add RTT calculations into it (for now). Although I agree that that is probably a good idea here.
I chose 2 seconds because then if one heartbeat packet is lost, we have enough time (probably) to send another one before the connection times out. Then again, this really depends on the idle_connection_timeout
value of the receiver, so the user currently has to adjust this value to their wishes anyway.
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.
Right, I can understand that I am not too certain about our RTT calculations as well, so I am fine with having this statically typed now. And figure out a way to do it based on the current internet speed in the future.
src/net/socket.rs
Outdated
if let Err(e) = self.handle_idle_clients(time) { | ||
error!("Encountered an error when sending TimeoutEvent: {:?}", e); | ||
} | ||
|
||
// Finally send heartbeat packets to connections that require them | ||
if let Err(e) = self.send_heartbeat_packets(time) { |
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.
As discussed, I prefer to have this optional.
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.
Sure, should it be enabled or disabled by default?
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.
Made heartbeats disabled by default, and the config value is now an Option<Duration>
, where None
disables and Some(Duration)
enables heartbeats.
Thanks for the PR, I do have one question are the acknowledgments also sent when the user only sents unreliable packets, because I don't see much-added value to have a heartbeat for those guarantees. |
I think the CI failure is spurious. I'm also working from windows and also saw it once (for no reason). Also I think something similar happened during my previous documentation-PR? |
I'm not quite sure what you mean, but heartbeats are currently send as unreliable and unordered, so there are no acknowledgments sent out for heartbeats atm. Did I understand your question correctly? |
Make sure that connections don't time out if we don't want them to, by regularly sending special, empty "heartbeat" packets on connections that we have not sent on for some time. The heartbeat interval can be configured and enabled/disabled via `Config::heartbeat_interval'.
I meant more in the way of, when sending packets, we can do use unreliably unordered to so for example. For unreliable packets, we do not have any internal state as we have for reliable ordered. So we might not care about the client to disconnect, on the other hand, I do think now, that you might also want to keep track of connected clients when only sending unreliable packets. So is not a direct problem, as long the heartbeat is optional im OK with it |
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.
This looks good to me 👍.
@TimonPost I believe that maintaining connection is an orthogonal concern to whether or not reliable packets are sent and having the option to ensure heartbeats are sent when a client is idling seems reasonable to me. |
Thanks for the review! :) |
Agreed, let's merge this! |
bors r=TimonPost, jstnlef |
224: Implement heartbeat functionality r=TimonPost,jstnlef a=futile Make sure that connections don't time out if we don't want them to, by regularly sending special, empty "heartbeat" packets on connections that we have not sent on for some time. These heartbeats have the new packet type `PacketType::Heartbeat`, which makes it possible to differentiate them from empty packets sent by a user. The heartbeat interval can be configured and disabled/enabled via `Config::heartbeat_interval`. ~~Note: Currently these heartbeats can not be explicity disabled (but you can set a very long heartbeat interval), but that should not be hard to add, if desired.~~ Edit: Heartbeats can now be disabled. Co-authored-by: Felix Rath <felix.rath@rwth-aachen.de>
Timed out |
Make sure that connections don't time out if we don't want them to, by
regularly sending special, empty "heartbeat" packets on connections that we
have not sent on for some time.
These heartbeats have the new packet type
PacketType::Heartbeat
, which makes it possible to differentiate them from empty packets sent by a user.The heartbeat interval can be configured and disabled/enabled via
Config::heartbeat_interval
.Note: Currently these heartbeats can not be explicity disabled (but you can set a very long heartbeat interval), but that should not be hard to add, if desired.Edit: Heartbeats can now be disabled.