Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 9838c9f

Browse files
niklasad1seunlanlege
authored andcommitted
Secret store: fix Instant::now() related race in net_keep_alive (#11155) (#11158)
* try Instant fix in SS * proper fix + add comment * fix compilation
1 parent 1a62f5a commit 9838c9f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

secret-store/src/key_server_cluster/cluster_connections_net.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,13 @@ fn net_maintain(data: Arc<NetConnectionsData>) {
467467

468468
/// Send keep alive messages to remote nodes.
469469
fn net_keep_alive(data: Arc<NetConnectionsData>) {
470-
let now = Instant::now();
471470
let active_connections = data.active_connections();
472471
for connection in active_connections {
473-
let last_message_diff = now - connection.last_message_time();
472+
// the last_message_time could change after active_connections() call
473+
// => we always need to call Instant::now() after getting last_message_time
474+
let last_message_time = connection.last_message_time();
475+
let now = Instant::now();
476+
let last_message_diff = now - last_message_time;
474477
if last_message_diff > KEEP_ALIVE_DISCONNECT_INTERVAL {
475478
warn!(target: "secretstore_net", "{}: keep alive timeout for node {}",
476479
data.self_key_pair.public(), connection.node_id());

0 commit comments

Comments
 (0)