Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix hang detection crash when foreground stats are missing (#58464)

Anthony Eidb76e0bc9ddda
diff --git a/crates/zed/src/reliability/hang_detection/logging.rs b/crates/zed/src/reliability/hang_detection/logging.rs
index c518d03ba14..940199dec5b 100644
--- a/crates/zed/src/reliability/hang_detection/logging.rs
+++ b/crates/zed/src/reliability/hang_detection/logging.rs
@@ -76,10 +76,9 @@ impl Reporter {
task_stats: &[gpui::ThreadTaskStatistics],
) -> ReportMade {
let foreground = self.foreground_thread;
- let foreground = task_stats
- .iter()
- .find(|t| t.thread_id == foreground)
- .expect("main thread should be in all statistics");
+ let Some(foreground) = task_stats.iter().find(|t| t.thread_id == foreground) else {
+ return false; // during startup the foreground may not yet have statistics
+ };
let hangs: Vec<_> = foreground
.stats
diff --git a/crates/zed/src/reliability/hang_detection/telemetry.rs b/crates/zed/src/reliability/hang_detection/telemetry.rs
index 4717cebe5a9..a2d8e4136a1 100644
--- a/crates/zed/src/reliability/hang_detection/telemetry.rs
+++ b/crates/zed/src/reliability/hang_detection/telemetry.rs
@@ -251,10 +251,10 @@ impl Reporter {
fn process_foreground(&mut self, task_stats: &[gpui::ThreadTaskStatistics]) {
let foreground_thread = self.foreground_thread;
- let foreground = task_stats
- .iter()
- .find(|t| t.thread_id == foreground_thread)
- .expect("main thread should be in all statistics");
+ let Some(foreground) = task_stats.iter().find(|t| t.thread_id == foreground_thread) else {
+ // during startup foreground thread might not have statistics yet
+ return;
+ };
for hang in foreground
.stats