fix: a panic on one thread no longer takes the whole app down

Every shared lock was std::sync::Mutex with lock().unwrap() (~150 sites),
so a panic in any session's reader or callback poisoned the lock and the
next UI frame panicked too, dropping every open session. Locks are now
parking_lot::Mutex (no poisoning; already in the dependency tree), and a
panic hook reports worker panics as an error toast instead of the session
silently stopping (F3, F4).
This commit is contained in:
Andy Dixon
2026-10-12 09:07:32 +01:00
parent afec95bb36
commit f09300fd95
28 changed files with 252 additions and 221 deletions
+5 -4
View File
@@ -13,9 +13,10 @@ use nexus_core::clients::sftp::{self as rsftp, FileEntry, Progress};
use nexus_core::keyfiles::safe_sftp_upload_name;
use nexus_core::models::Protocol;
use nexus_core::service::Service;
use parking_lot::Mutex;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::sync::Arc;
/// Worker results, applied on the UI thread.
enum Done {
@@ -47,7 +48,7 @@ struct Inbox(Arc<Mutex<Vec<Done>>>, egui::Context);
impl Inbox {
fn push(&self, d: Done) {
self.0.lock().unwrap().push(d);
self.0.lock().push(d);
self.1.request_repaint();
}
}
@@ -250,7 +251,7 @@ impl Sftp {
let tr = self.transfers.remove(i);
if self.open_for.as_deref() != Some(session) {
let verb = if tr.upload { "↑ Uploaded" } else { "↓ Downloaded" };
self.inbox.lock().unwrap().push(Done::Toast(format!("{verb} {}", base_name(&tr.path))));
self.inbox.lock().push(Done::Toast(format!("{verb} {}", base_name(&tr.path))));
}
}
}
@@ -269,7 +270,7 @@ impl Sftp {
}
fn drain(&mut self, s: &mut Shared) {
let items = std::mem::take(&mut *self.inbox.lock().unwrap());
let items = std::mem::take(&mut *self.inbox.lock());
for d in items {
match d {
Done::Listed { session, path, files } => {