1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

fix(cli): occasional panics on progress bar (#22809)

Uses `Instant` instead of `SystemTime` for
`cli/util/progress_bar/mod.rs`. Fixes #22558
This commit is contained in:
tuhana 2024-03-09 00:27:58 +03:00 committed by GitHub
parent 5d85efd595
commit 66d1b155dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,7 +3,7 @@
use std::sync::atomic::AtomicU64; use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use std::sync::Arc; use std::sync::Arc;
use std::time::SystemTime; use std::time::Instant;
use deno_core::parking_lot::Mutex; use deno_core::parking_lot::Mutex;
use deno_runtime::ops::tty::ConsoleSize; use deno_runtime::ops::tty::ConsoleSize;
@ -122,7 +122,7 @@ struct InternalState {
/// If this guard exists, then it means the progress /// If this guard exists, then it means the progress
/// bar is displaying in the draw thread. /// bar is displaying in the draw thread.
draw_thread_guard: Option<DrawThreadGuard>, draw_thread_guard: Option<DrawThreadGuard>,
start_time: SystemTime, start_time: Instant,
keep_alive_count: usize, keep_alive_count: usize,
total_entries: usize, total_entries: usize,
entries: Vec<ProgressBarEntry>, entries: Vec<ProgressBarEntry>,
@ -139,7 +139,7 @@ impl ProgressBarInner {
Self { Self {
state: Arc::new(Mutex::new(InternalState { state: Arc::new(Mutex::new(InternalState {
draw_thread_guard: None, draw_thread_guard: None,
start_time: SystemTime::now(), start_time: Instant::now(),
keep_alive_count: 0, keep_alive_count: 0,
total_entries: 0, total_entries: 0,
entries: Vec::new(), entries: Vec::new(),
@ -207,7 +207,7 @@ impl ProgressBarInner {
if internal_state.draw_thread_guard.is_none() if internal_state.draw_thread_guard.is_none()
&& internal_state.keep_alive_count > 0 && internal_state.keep_alive_count > 0
{ {
internal_state.start_time = SystemTime::now(); internal_state.start_time = Instant::now();
internal_state.draw_thread_guard = internal_state.draw_thread_guard =
Some(DrawThread::add_entry(Arc::new(self.clone()))); Some(DrawThread::add_entry(Arc::new(self.clone())));
} }
@ -228,7 +228,7 @@ impl DrawThreadRenderer for ProgressBarInner {
.or_else(|| state.entries.iter().last()) .or_else(|| state.entries.iter().last())
.unwrap(); .unwrap();
ProgressData { ProgressData {
duration: state.start_time.elapsed().unwrap(), duration: state.start_time.elapsed(),
terminal_width: size.cols, terminal_width: size.cols,
pending_entries: state.entries.len(), pending_entries: state.entries.len(),
total_entries: state.total_entries, total_entries: state.total_entries,