Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Crash reports: a freeze over before its snapshot says so (#355) (#400)

Ahmed Nefzaoui55d14b22f81c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1ea2b0f1..766c0fa1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- Crash reports: a freeze that was over before its snapshot was taken says so, instead of calling it a deadlock in code that was only waiting for events ([#355](https://github.com/anefzaoui/misterdownloadmanager/issues/355)).
- **Move/Rename** was greyed out with several downloads selected, for example a set just added to a queue. It now asks for a folder and moves them all there ([#333](https://github.com/anefzaoui/misterdownloadmanager/issues/333)).
- The extension no longer asks you to update MDM when only a bug-fix version separates them, which it did even when there was no update to get.
- **Download video** shows a plain file's size, from its server, instead of "size unknown" ([#320](https://github.com/anefzaoui/misterdownloadmanager/issues/320)).
diff --git a/ROADMAP.md b/ROADMAP.md
index 21f028fc..a7915560 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -13,6 +13,8 @@ Everything below ships together, in version 0.5.0.
### Done
+- ✅ Freeze reports taken after the window has already answered say so, instead of blaming a deadlock
+ (part of [#355](https://github.com/anefzaoui/misterdownloadmanager/issues/355))
- ✅ **Move/Rename** works on several selected downloads at once: pick a folder and they all go there
([#333](https://github.com/anefzaoui/misterdownloadmanager/issues/333))
- ✅ Download video shows the size of a plain file (what the server says), not "size unknown"
diff --git a/crates/crash/src/report.rs b/crates/crash/src/report.rs
index 93c399ef..955fdece 100644
--- a/crates/crash/src/report.rs
+++ b/crates/crash/src/report.rs
@@ -70,6 +70,23 @@ pub fn text(input: &Input, home: Option<&Path>) -> String {
}
Kind::Freeze => {
match &input.notes.freeze {
+ Some(f) if f.seconds > 0 && over_before_snapshot(kind, input) => {
+ let ran = f
+ .busy
+ .map(|b| {
+ format!(
+ " Its thread ran {:.1} of {:.1} s while it did not answer.",
+ b.cpu_ms as f64 / 1000.0,
+ b.wall_ms as f64 / 1000.0
+ )
+ })
+ .unwrap_or_default();
+ let _ = writeln!(
+ s,
+ "The window did not answer for {} s, but it was back to waiting for events when this snapshot was taken, so the stacks below don't show what held it.{ran}",
+ f.seconds
+ );
+ }
Some(f) if f.seconds > 0 => {
let top = key_thread(kind, input).and_then(|t| t.frames.first());
let secs = |ms: u64| format!("{:.1}", ms as f64 / 1000.0);
@@ -341,6 +358,11 @@ pub fn description(kind: Kind, notes: &Notes) -> &'static str {
/// matters ("freeze in misterdownloadmanager::winui::combo_edit").
pub fn signature(kind: Kind, input: &Input) -> String {
let main_module = main_module(input);
+ // The freeze ended before the snapshot: its stack says nothing about it, and without this
+ // every such report was filed under the start-up function that runs the event loop (#355).
+ if over_before_snapshot(kind, input) {
+ return format!("{} over before the snapshot", kind.word());
+ }
// A computer too busy to run MDM: one name for all of them, wherever the thread happened to be.
if let Some(f) = input.notes.freeze.as_ref().filter(|_| kind == Kind::Freeze) {
let top = key_thread(kind, input).and_then(|t| t.frames.first());
@@ -485,6 +507,22 @@ fn key_thread<'a>(kind: Kind, input: &Input<'a>) -> Option<&'a Thread> {
a.thread(a.requesting?)
}
+/// A freeze whose window thread was already back in the event loop's wait when the dump was taken:
+/// a frame in progress never has that on its stack, so the frame had ended. The dump follows the
+/// watchdog's request, and came 7 s after it on a stalled computer (#355). winit's wait, on Windows;
+/// other systems' stacks keep the verdicts below.
+fn over_before_snapshot(kind: Kind, input: &Input) -> bool {
+ kind == Kind::Freeze
+ && input.notes.freeze.is_some()
+ && key_thread(kind, input).is_some_and(|t| {
+ t.frames.iter().any(|f| {
+ f.function
+ .as_deref()
+ .is_some_and(|n| n.contains("wait_for_messages"))
+ })
+ })
+}
+
/// The first frame in the program's own code, past the system, Rust's standard library, locks,
/// panics and the crash reporter itself: a function of the program's own crates first (named as
/// its main module, the dump's first: "misterdownloadmanager", or MDM's `mdm_*` crates), else
@@ -804,6 +842,41 @@ mod tests {
);
}
+ /// #355, as reported: the dump was written 7 s after it was asked for, when the window thread
+ /// was back in the event loop. Not a deadlock, not "in misterdownloadmanager::app".
+ #[test]
+ fn a_freeze_over_before_the_snapshot_says_so() {
+ let mut a = frozen();
+ a.threads[0].frames = vec![
+ Frame {
+ function: None,
+ file: None,
+ line: None,
+ module: Some("win32u.dll".into()),
+ offset: 0xa124,
+ },
+ frame(
+ "winit::platform_impl::windows::event_loop::EventLoop::wait_for_messages<enum2$<eframe::native::winit_integration::UserEvent> >",
+ ),
+ frame("eframe::run_native"),
+ frame("misterdownloadmanager::app"),
+ frame("misterdownloadmanager::main"),
+ ];
+ let input = freeze_with(&a, 0);
+ assert_eq!(
+ signature(Kind::Freeze, &input),
+ "freeze over before the snapshot"
+ );
+ let t = text(&input, None);
+ assert!(
+ t.contains("back to waiting for events when this snapshot was taken"),
+ "{t}"
+ );
+ assert!(t.contains("Its thread ran 0.0 of 7.5 s"), "{t}");
+ assert!(!t.contains("deadlock"), "{t}");
+ assert!(!t.contains("one frame never finished"), "{t}");
+ }
+
#[test]
fn a_freeze_in_a_lock_is_a_wait_and_keeps_its_place() {
let a = frozen();
diff --git a/docs/crash-reports.md b/docs/crash-reports.md
index abc57f16..68d663b7 100644
--- a/docs/crash-reports.md
+++ b/docs/crash-reports.md
@@ -51,7 +51,7 @@ The log records what MDM does, so a report can show what led to a problem. To lo
How it works: a second copy of MDM, the **monitor**, starts beside it with `--crash-monitor`. The crash code lives in `crates/crash` and `crates/app/src/crash.rs`.
-- **Catching problems.** When MDM crashes (a Windows exception, a signal on Linux, a Mach exception on macOS), panics, or freezes, it asks the monitor for a dump. A freeze is a frame of the window running more than 8 s, seen by a watchdog thread that ignores time spent asleep. It times both parts of a frame: what MDM handles (the commands that come in, the clock of downloads, queues and the Scheduler), which runs minimized too, and the drawing; never the wait between frames. The watchdog also measures how much processor time the window thread got meanwhile, and the report says what that means: it ran all along (a loop), it waited in a lock or on I/O (a deadlock), or it hardly ran in ordinary code, which is a computer too busy to run MDM or slow to load it from disk, most likely not MDM's bug (those share one signature, `freeze while the computer was busy`). macOS doesn't measure it yet. The monitor then writes a **minidump** of every thread from outside, through `minidumper` and `crash-handler`. A crashed process never writes its own dump, which is how Firefox, Crashpad and Sentry do it too.
+- **Catching problems.** When MDM crashes (a Windows exception, a signal on Linux, a Mach exception on macOS), panics, or freezes, it asks the monitor for a dump. A freeze is a frame of the window running more than 8 s, seen by a watchdog thread that ignores time spent asleep. It times both parts of a frame: what MDM handles (the commands that come in, the clock of downloads, queues and the Scheduler), which runs minimized too, and the drawing; never the wait between frames. The watchdog also measures how much processor time the window thread got meanwhile, and the report says what that means: it ran all along (a loop), it waited in a lock or on I/O (a deadlock), or it hardly ran in ordinary code, which is a computer too busy to run MDM or slow to load it from disk, most likely not MDM's bug (those share one signature, `freeze while the computer was busy`). When the window thread is already back in the event loop by the time the dump is written, the freeze was over before the snapshot, so its stack can't explain it; those reports say so and share the signature `freeze over before the snapshot`. macOS doesn't measure it yet. The monitor then writes a **minidump** of every thread from outside, through `minidumper` and `crash-handler`. A crashed process never writes its own dump, which is how Firefox, Crashpad and Sentry do it too.
- **Reading the dump.** The monitor reads the dump with Mozilla's `rust-minidump`. It uses the release's Breakpad symbols when they are found. A build from source can also read the native debug info beside it (its `.pdb`, DWARF) when built with `--features mdm-crash/native-symbols`; the shipped app goes without that reader, several MB. The report's **Signature** (for example `freeze in misterdownloadmanager::winui::combo_edit`) stays the same across reports of one problem, and the window searches existing issues for it.
- **Symbols.** Release builds keep line tables (`debug = "line-tables-only"`), but no download includes the debug info. CI turns it into `MisterDownloadManager-<version>-symbols-<platform>.zip` (`tools/installer/symbols.py`, using Mozilla's `dump_syms`), published beside the release's other files. The report window fetches the zip for its own version when a stack shows bare addresses.
- **A `.dmp` from an issue:**