From 298ca6f23afa0aef11b1aa6f8da73230fbc78d48 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Wed, 22 Sep 2021 13:15:01 +0200 Subject: [PATCH] Fix CW tick events endless loop at shutdown Fixed an edge case with console wallet shutdown where the tick events send loop will continue to send key events after the receiver part of the channel has been closed. --- .../src/utils/crossterm_events.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/applications/tari_console_wallet/src/utils/crossterm_events.rs b/applications/tari_console_wallet/src/utils/crossterm_events.rs index cbf2927a23..b16bff0e8f 100644 --- a/applications/tari_console_wallet/src/utils/crossterm_events.rs +++ b/applications/tari_console_wallet/src/utils/crossterm_events.rs @@ -70,8 +70,10 @@ impl CrosstermEvents { ) { Ok(true) => { if let Ok(CEvent::Key(key)) = event::read() { - if let Err(e) = tx.send(Event::Input(key)) { - warn!(target: LOG_TARGET, "Error sending Tick event on MPSC channel: {}", e); + if tx.send(Event::Input(key)).is_err() { + info!(target: LOG_TARGET, "Tick event channel shutting down"); + // A send operation can only fail if the receiving end of a channel is disconnected. + break; } } }, @@ -81,8 +83,10 @@ impl CrosstermEvents { }, } if last_tick.elapsed() >= config.tick_rate { - if let Err(e) = tx.send(Event::Tick) { - warn!(target: LOG_TARGET, "Error sending Tick event on MPSC channel: {}", e); + if tx.send(Event::Tick).is_err() { + info!(target: LOG_TARGET, "Tick event channel shutting down"); + // A send operation can only fail if the receiving end of a channel is disconnected. + break; } last_tick = Instant::now(); }