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 background task panicking while MDM closes is no crash (#422) (#434)

Ahmed Nefzaouicf9b0973c68c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6934610f..b467911c 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: no report any more when one of the download engine's background tasks panics while MDM is already closing ([#422](https://github.com/anefzaoui/misterdownloadmanager/issues/422)).
- Crash reports: a freeze whose window had recovered by the time its dump was taken is reported as a freeze, not as a crash in MDM's own watchdog ([#420](https://github.com/anefzaoui/misterdownloadmanager/issues/420)).
- Text in a script outside the interface language (a video title in Bangla, a playlist in Japanese) now shows its letters, instead of boxes: the font for that script is loaded the first time it is needed ([#405](https://github.com/anefzaoui/misterdownloadmanager/issues/405)).
- Options → Proxy / Socks now applies to yt-dlp and gallery-dl too, so video look-ups and downloads no longer go straight out when a proxy is set ([#363](https://github.com/anefzaoui/misterdownloadmanager/issues/363)).
diff --git a/ROADMAP.md b/ROADMAP.md
index cfe99d43..f7c38e89 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -13,6 +13,8 @@ Everything below ships together, in version 0.5.0.
### Done
+- ✅ A background task stopping as MDM closes no longer shows a crash report
+ ([#422](https://github.com/anefzaoui/misterdownloadmanager/issues/422))
- ✅ A freeze that was over before its dump was taken is reported as a freeze, not a crash in the
watchdog (part of [#420](https://github.com/anefzaoui/misterdownloadmanager/issues/420))
- ✅ File names and titles in any script show their letters: the system font for a script
diff --git a/crates/app/src/crash.rs b/crates/app/src/crash.rs
index 34feaf3b..0f2c2058 100644
--- a/crates/app/src/crash.rs
+++ b/crates/app/src/crash.rs
@@ -121,6 +121,10 @@ fn hook_panics() {
backtrace: std::backtrace::Backtrace::force_capture().to_string(),
};
tracing::error!("panic: {} at {} ({})", p.message, p.location, p.thread);
+ if !panic_reported(CLOSING.load(Ordering::Acquire), &p.thread) {
+ default(info);
+ return;
+ }
if let Some(r) = REPORTER.get()
&& !PANICKED.swap(true, Ordering::AcqRel)
{
@@ -205,8 +209,18 @@ pub fn state(downloads: usize, running: usize, queues: usize, scale: f32) {
});
}
+/// MDM has started closing normally: what panics on the runtime's own threads now (a task's
+/// timer once the runtime is shutting down, #422) is the runtime going away, not a problem.
+static CLOSING: AtomicBool = AtomicBool::new(false);
+
+/// Is this panic worth a report? Not one on a runtime worker while MDM is closing (#422).
+fn panic_reported(closing: bool, thread: &str) -> bool {
+ !(closing && thread.starts_with("tokio"))
+}
+
/// MDM is closing normally: the monitor leaves without a report.
pub fn clean_exit() {
+ CLOSING.store(true, Ordering::Release);
if let Some(r) = REPORTER.get() {
tracing::info!("closing");
r.clean();
@@ -378,3 +392,15 @@ fn crash_test_freeze() {
let _held = lock.lock();
let _never = lock.lock();
}
+
+#[cfg(test)]
+mod closing_tests {
+ /// #422: a Tokio task panicking while MDM closes is no crash; the window thread's would be.
+ #[test]
+ fn a_runtime_panic_while_closing_is_not_reported() {
+ use super::panic_reported;
+ assert!(!panic_reported(true, "tokio-rt-worker"));
+ assert!(panic_reported(false, "tokio-rt-worker"));
+ assert!(panic_reported(true, "main"));
+ }
+}