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.
schreter authored and drmingdrmer committed Nov 28, 2023
1 parent f469878 commit 2c715d6
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
@@ -62,8 +62,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)
}

0 comments on commit 2c715d6

Please sign in to comment.