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

* try Instant fix in SS

* proper fix + add comment

* fix compilation
This commit is contained in:
Niklas Adolfsson 2019-10-10 16:52:09 +02:00 committed by Seun LanLege
parent 1a62f5a086
commit 9838c9f447

View File

@ -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());