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

Commit

Permalink
Secret store: fix Instant::now() related race in net_keep_alive (#11155
Browse files Browse the repository at this point in the history
…) (#11158)

* try Instant fix in SS

* proper fix + add comment

* fix compilation
  • Loading branch information
niklasad1 authored and seunlanlege committed Oct 10, 2019
1 parent 1a62f5a commit 9838c9f
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,13 @@ fn net_maintain(data: Arc<NetConnectionsData>) {

/// Send keep alive messages to remote nodes.
fn net_keep_alive(data: Arc<NetConnectionsData>) {
let now = Instant::now();
let active_connections = data.active_connections();
for connection in active_connections {
let last_message_diff = now - connection.last_message_time();
// the last_message_time could change after active_connections() call
// => we always need to call Instant::now() after getting last_message_time
let last_message_time = connection.last_message_time();
let now = Instant::now();
let last_message_diff = now - last_message_time;
if last_message_diff > KEEP_ALIVE_DISCONNECT_INTERVAL {
warn!(target: "secretstore_net", "{}: keep alive timeout for node {}",
data.self_key_pair.public(), connection.node_id());
Expand Down

0 comments on commit 9838c9f

Please sign in to comment.