Skip to content

Commit

Permalink
fix(protocols/kad): update KeepAlive::Until to preserve existing dead…
Browse files Browse the repository at this point in the history
…line

Previous to this change if the ConnectionHandler::poll for kad was called more frequently than the
connection idle timeout the timeout would continually be pushed further into the feature. After this
change kad now will preserve the existing idle deadline.
  • Loading branch information
nathanielc committed Apr 18, 2023
1 parent 96288b8 commit 3991197
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion protocols/kad/src/handler_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,13 @@ where

if self.outbound_substreams.is_empty() && self.inbound_substreams.is_empty() {
// We destroyed all substreams in this function.
self.keep_alive = KeepAlive::Until(Instant::now() + self.config.idle_timeout);
self.keep_alive = if let KeepAlive::Until(time) = self.keep_alive {
// Preserve the existing idle timeout
KeepAlive::Until(time)
} else {
// Setup idle timeout
KeepAlive::Until(Instant::now() + self.config.idle_timeout)
};
} else {
self.keep_alive = KeepAlive::Yes;
}
Expand Down

0 comments on commit 3991197

Please sign in to comment.