From 3f24aaf2b278e03b7193b9bc5a2d99784cfc42df Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:51:49 +0200 Subject: [PATCH] fix: potential deadlock in the consensus ticker on close Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- tm2/pkg/bft/consensus/ticker.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tm2/pkg/bft/consensus/ticker.go b/tm2/pkg/bft/consensus/ticker.go index 8448e014260..461a93e3e6e 100644 --- a/tm2/pkg/bft/consensus/ticker.go +++ b/tm2/pkg/bft/consensus/ticker.go @@ -67,8 +67,13 @@ func (t *timeoutTicker) Chan() <-chan timeoutInfo { // ScheduleTimeout schedules a new timeout by sending on the internal tickChan. // The timeoutRoutine is always available to read from tickChan, so this won't block. // The scheduling may fail if the timeoutRoutine has already scheduled a timeout for a later height/round/step. +// If the service has been closed, the timeout will be ignored. func (t *timeoutTicker) ScheduleTimeout(ti timeoutInfo) { - t.tickChan <- ti + select { + case t.tickChan <- ti: + case <-t.Quit(): + t.Logger.Warn("Unable to schedule timeout as service has been closed") + } } // -------------------------------------------------------------