diff --git a/src/traft/network.rs b/src/traft/network.rs index c8cb14687ee00b6b88563a30bb186cd01f89a5bf..25613ef391d2649d49d8201e6a3dc2266a79615b 100644 --- a/src/traft/network.rs +++ b/src/traft/network.rs @@ -224,8 +224,6 @@ impl PoolWorker { poll_fn(|cx| { let mut has_ready: bool = false; let mut cursor = 0; - // NOTE: must not yield until this is dropped. - let mut reachability = instance_reachability.borrow_mut(); while cursor < futures.len() { let poll_result = Future::poll(futures[cursor].2.as_mut(), cx); if let Poll::Ready(result) = poll_result { @@ -260,7 +258,9 @@ impl PoolWorker { | TOError::Failed(NetError::Io(_)) ); } - reachability.report_result(raft_id, success); + instance_reachability + .borrow_mut() + .report_result(raft_id, success); } } has_ready = true; diff --git a/src/traft/node.rs b/src/traft/node.rs index 2e0b7129f8487328f6db48be3a43745e7545ac82..7aba644a7f855629c32288ab6dd68f110cb0ef63 100644 --- a/src/traft/node.rs +++ b/src/traft/node.rs @@ -1403,13 +1403,13 @@ impl NodeImpl { let mut sent_count = 0; let mut skip_count = 0; - let instance_reachability = self.instance_reachability.borrow(); for msg in messages { - if msg.msg_type == raft::MessageType::MsgHeartbeat - && !instance_reachability.should_send_heartbeat_this_tick(msg.to) - { - skip_count += 1; - continue; + if msg.msg_type == raft::MessageType::MsgHeartbeat { + let instance_reachability = self.instance_reachability.borrow(); + if !instance_reachability.should_send_heartbeat_this_tick(msg.to) { + skip_count += 1; + continue; + } } sent_count += 1; if let Err(e) = self.pool.send(msg) {