Skip to content

Commit

Permalink
Fix: End tick_loop() when the receiver is gone.
Browse files Browse the repository at this point in the history
Currently, `tick_loop()` would keep printing the trace message every
tick even when the receiver (Raft main loop) is gone in this form:

`INFO openraft::core::tick: .../tick.rs:70: Tick fails to send, receiving end quit: channel closed`

If the tick message fails to send, then terminate the loop, since every
future message will fail to send as well.

Also adjust the trace message to better describe what happened.
  • Loading branch information
schreter authored and drmingdrmer committed Nov 14, 2023
1 parent 3b405c8 commit f41729a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions openraft/src/core/tick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ where C: RaftTypeConfig
}

let send_res = self.tx.send(Notify::Tick { i });
if let Err(e) = send_res {
tracing::info!("Tick fails to send, receiving end quit: {e}");
if let Err(_e) = send_res {
tracing::info!("Stopping tick_loop(), main loop terminated");
break;
} else {
tracing::debug!("Tick sent: {}", i)
}
Expand Down

0 comments on commit f41729a

Please sign in to comment.