misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
fix(crash): clean up failed crash-monitor processes (#458)
awishtodiexz8f7847985bea
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0962379e..f2e478e8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see### Fixed+- Crash reports: a crash monitor that can't open its connection no longer makes MDM wait five seconds at start or stays behind as a second process ([#458](https://github.com/anefzaoui/misterdownloadmanager/pull/458)).- Download File Info no longer stays open but out of sight, with every later download waiting behind it ([#440](https://github.com/anefzaoui/misterdownloadmanager/issues/440)). The next one after answering **Create folder** came up as an invisible window, and on Windows one hidden with a minimized main window is now shown again, as is the duplicate question- A file name sent by a site in plain UTF-8 now reaches MDM readable from Firefox and browsers built on it, such as Floorp, Waterfox and Zen: an Arabic name was saved as unreadable symbols ([#447](https://github.com/anefzaoui/misterdownloadmanager/issues/447)). A name written with percent signs in the same header is decoded as well. The add-on carries the fix- A download saved under a numbered name because another file already had its name (`master (1).mp4`) now shows that name in the list and opens its own file, instead of keeping the old name and opening the other file ([#442](https://github.com/anefzaoui/misterdownloadmanager/issues/442)). Two downloads waiting under one name no longer collide when they start: the later one takes the next free name, instead of failing with "already being downloaded" or continuing the other one's data.diff --git a/ROADMAP.md b/ROADMAP.mdindex 3c26c2eb..0de0b47e 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -544,6 +544,9 @@ These ship in a later version, when they're ready.- 🔍 A 10-second freeze of the window after a night left open([#304](https://github.com/anefzaoui/misterdownloadmanager/issues/304)): most likely thecomputer waking from sleep; waiting on the reporter's full report+- 🔄 Crash reports: a monitor that cannot open its socket exits, and an unreachable one is+ cleaned up instead of staying beside MDM: fix in review+ ([#458](https://github.com/anefzaoui/misterdownloadmanager/pull/458))## Planneddiff --git a/crates/app/src/crashui.rs b/crates/app/src/crashui.rsindex 50495359..291271b6 100644--- a/crates/app/src/crashui.rs+++ b/crates/app/src/crashui.rs@@ -32,10 +32,12 @@ pub fn monitor_main(m: MonitorArgs) -> eframe::Result {);let (tx, rx) = channel();{- let (socket, data, tx) = (m.socket.clone(), m.data.clone(), tx.clone());+ let (socket, data, tx, failed) = (m.socket.clone(), m.data.clone(), tx.clone(), tx.clone());std::thread::spawn(move || {if let Err(e) = monitor::serve(&socket, &data, tx) {- tracing::error!("crash monitor: {e}");+ // The app can't connect: say so, rather than waiting beside it as a second+ // process that can never report anything.+ let _ = failed.send(Event::ServeFailed(e));}});}@@ -72,6 +74,10 @@ pub fn monitor_main(m: MonitorArgs) -> eframe::Result {return Ok(());}Ok(Event::Recovered) => {}+ Ok(Event::ServeFailed(e)) => {+ tracing::error!("crash monitor: {e}");+ return Ok(());+ }Err(_) => return Ok(()),}};diff --git a/crates/crash/examples/crashy.rs b/crates/crash/examples/crashy.rsindex 1021938a..57f9db5f 100644--- a/crates/crash/examples/crashy.rs+++ b/crates/crash/examples/crashy.rs@@ -128,8 +128,11 @@ fn os_thread_id() -> u32 {fn run_monitor(m: mdm_crash::MonitorArgs) {let (tx, rx) = std::sync::mpsc::channel();let (socket, data) = (m.socket.clone(), m.data.clone());+ let failed = tx.clone();std::thread::spawn(move || {- let _ = monitor::serve(&socket, &data, tx);+ if let Err(e) = monitor::serve(&socket, &data, tx) {+ let _ = failed.send(Event::ServeFailed(e));+ }});while let Ok(e) = rx.recv() {match e {@@ -139,6 +142,10 @@ fn run_monitor(m: mdm_crash::MonitorArgs) {}Event::DumpFailed { error, .. } => eprintln!("monitor: dump failed: {error}"),Event::Recovered => {}+ Event::ServeFailed(e) => {+ eprintln!("monitor: {e}");+ break;+ }Event::Gone { .. } => break,}}diff --git a/crates/crash/src/client.rs b/crates/crash/src/client.rsindex 9267ec4c..75b3c976 100644--- a/crates/crash/src/client.rs+++ b/crates/crash/src/client.rs@@ -29,7 +29,7 @@ impl Reporter {.arg(data).arg("--parent").arg(std::process::id().to_string());- let child = match cmd.spawn() {+ let mut child = match cmd.spawn() {Ok(c) => c,Err(e) => {tracing::warn!("crash monitor didn't start: {e}");@@ -41,10 +41,19 @@ impl Reporter {match minidumper::Client::with_name(minidumper::SocketName::Path(&socket)) {Ok(c) => break c,Err(_) if Instant::now() < deadline => {+ // A monitor that couldn't open its socket has already said why in its own+ // log and gone: don't make the app wait the whole five seconds for it.+ if let Ok(Some(_)) = child.try_wait() {+ tracing::warn!("crash monitor exited before it listened");+ return None;+ }std::thread::sleep(Duration::from_millis(25))}Err(e) => {tracing::warn!("crash monitor didn't answer: {e}");+ // It can never answer now: don't leave a second MDM process behind.+ let _ = child.kill();+ let _ = child.wait();return None;}}@@ -113,3 +122,30 @@ impl Reporter {self.client.request_dump(context).is_ok()}}++#[cfg(test)]+mod tests {+ use super::*;++ /// A monitor that couldn't open its socket exits at once: the app doesn't wait its five+ /// seconds for a process that is already gone.+ #[test]+ fn a_monitor_that_exits_before_listening_is_not_waited_for() {+ let dir = tempfile::tempdir().unwrap();+ // A system program that starts and exits at once; the monitor's arguments mean nothing+ // to it.+ let exe = if cfg!(windows) {+ "whoami.exe"+ } else {+ // macOS has no /bin/true: found on the PATH.+ "true"+ };+ let started = Instant::now();+ assert!(Reporter::start(Path::new(exe), dir.path()).is_none());+ assert!(+ started.elapsed() < Duration::from_secs(2),+ "waited {:?} for a monitor that had already gone",+ started.elapsed()+ );+ }+}diff --git a/crates/crash/src/monitor.rs b/crates/crash/src/monitor.rsindex 6a4b04a4..3cfe0223 100644--- a/crates/crash/src/monitor.rs+++ b/crates/crash/src/monitor.rs@@ -26,6 +26,8 @@ pub enum Event {},/// The window answers again after a freeze.Recovered,+ /// The socket couldn't be opened: the app can never connect, so stop waiting for it.+ ServeFailed(String),/// The app is gone: `clean` when it closed normally.Gone { clean: bool, notes: Notes },}