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

Secret store: fix Instant::now() related race in net_keep_alive #11155

Merged
merged 3 commits into from
Oct 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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