From bbd3a7e637b0223647405adf76b23092ab957157 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 23 Aug 2024 18:07:59 -0400 Subject: [PATCH] fix: handle showing warnings while the progress bar is shown (#25187) --- cli/util/draw_thread.rs | 17 ++++++++++------- cli/util/logger.rs | 8 ++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cli/util/draw_thread.rs b/cli/util/draw_thread.rs index d9ab176a93..164a8fc713 100644 --- a/cli/util/draw_thread.rs +++ b/cli/util/draw_thread.rs @@ -40,7 +40,7 @@ struct InternalEntry { struct InternalState { // this ensures only one actual draw thread is running drawer_id: usize, - hide: bool, + hide_count: usize, has_draw_thread: bool, next_entry_id: u16, entries: Vec, @@ -56,7 +56,7 @@ impl InternalState { static INTERNAL_STATE: Lazy>> = Lazy::new(|| { Arc::new(Mutex::new(InternalState { drawer_id: 0, - hide: false, + hide_count: 0, has_draw_thread: false, entries: Vec::new(), next_entry_id: 0, @@ -113,7 +113,7 @@ impl DrawThread { pub fn hide() { let internal_state = &*INTERNAL_STATE; let mut internal_state = internal_state.lock(); - internal_state.hide = true; + internal_state.hide_count += 1; Self::clear_and_stop_draw_thread(&mut internal_state); } @@ -122,9 +122,12 @@ impl DrawThread { pub fn show() { let internal_state = &*INTERNAL_STATE; let mut internal_state = internal_state.lock(); - internal_state.hide = false; - - Self::maybe_start_draw_thread(&mut internal_state); + if internal_state.hide_count > 0 { + internal_state.hide_count -= 1; + if internal_state.hide_count == 0 { + Self::maybe_start_draw_thread(&mut internal_state); + } + } } fn finish_entry(entry_id: u16) { @@ -153,7 +156,7 @@ impl DrawThread { fn maybe_start_draw_thread(internal_state: &mut InternalState) { if internal_state.has_draw_thread - || internal_state.hide + || internal_state.hide_count > 0 || internal_state.entries.is_empty() || !DrawThread::is_supported() { diff --git a/cli/util/logger.rs b/cli/util/logger.rs index 4c185f6de4..d64e9a707b 100644 --- a/cli/util/logger.rs +++ b/cli/util/logger.rs @@ -2,6 +2,8 @@ use std::io::Write; +use super::draw_thread::DrawThread; + struct CliLogger(env_logger::Logger); impl CliLogger { @@ -21,7 +23,13 @@ impl log::Log for CliLogger { fn log(&self, record: &log::Record) { if self.enabled(record.metadata()) { + // it was considered to hold the draw thread's internal lock + // across logging, but if outputting to stderr blocks then that + // could potentially block other threads that access the draw + // thread's state + DrawThread::hide(); self.0.log(record); + DrawThread::show(); } }