Crash reports: a repeated panic that ends the app is counted, not reported as an unclean exit (#6051) (#6052)
* claim: #6051 * Crash reports: a repeated panic that ends the app is counted, not reported as an unclean exit (#6051)
This commit is contained in:
@@ -420,18 +420,31 @@ fn hook(info: &std::panic::PanicHookInfo<'_>) -> bool {
|
||||
let sig = signature(&location, &message);
|
||||
let recovered = solidcraft_kernel::guarded();
|
||||
let in_command = IN_COMMAND.with(Cell::get) > 0;
|
||||
// Already reported (this run or before): count it, nothing else.
|
||||
let repeat = match state.known.lock() {
|
||||
Ok(mut k) => match k.get_mut(&sig) {
|
||||
Some(e) => {
|
||||
let quiet = recovered || in_command;
|
||||
// Already reported (this run or before): count it, nothing else. A panic outside commands
|
||||
// can end the app before `end_session` writes the counts, so its count goes to the report
|
||||
// now, and the journal says it was reported (or the next start reports an unclean exit).
|
||||
let known = state.known.lock().map(|mut k| {
|
||||
k.get_mut(&sig).map(|e| {
|
||||
if quiet {
|
||||
e.0 += 1;
|
||||
true
|
||||
}
|
||||
None => false,
|
||||
},
|
||||
e.1.clone()
|
||||
})
|
||||
});
|
||||
let repeat = match known {
|
||||
Ok(Some(id)) => {
|
||||
if !quiet {
|
||||
bump(&state.dir, &id, 1);
|
||||
if let Ok(mut j) = state.journal.try_lock() {
|
||||
j.record(&json!({ "reported": id }));
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
Ok(None) => false,
|
||||
Err(_) => true,
|
||||
};
|
||||
let quiet = recovered || in_command;
|
||||
if repeat {
|
||||
IN_HOOK.store(false, Ordering::SeqCst);
|
||||
return quiet;
|
||||
|
||||
@@ -64,13 +64,17 @@ fn child() {
|
||||
"kernel" => {
|
||||
assert!(s.execute("diagnostics.crash_test", &json!({"mode": "kernel"})).is_err());
|
||||
}
|
||||
"thread" => {
|
||||
// `thread_dies`: the panic ends the app, as one on the window's thread does.
|
||||
"thread" | "thread_dies" => {
|
||||
let r = std::thread::Builder::new()
|
||||
.name("worker".into())
|
||||
.spawn(|| std::panic::panic_any(String::from("worker thread 42 failed")))
|
||||
.unwrap()
|
||||
.join();
|
||||
assert!(r.is_err());
|
||||
if mode == "thread_dies" {
|
||||
std::process::abort();
|
||||
}
|
||||
}
|
||||
"abort" => {
|
||||
let _ = s.execute("diagnostics.crash_test", &json!({"mode": "abort"}));
|
||||
@@ -166,6 +170,21 @@ fn a_panic_outside_commands_is_reported() {
|
||||
let _ = fs::remove_dir_all(&d);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_known_panic_that_ends_the_app_is_counted_not_reported_again_as_an_unclean_exit() {
|
||||
let d = fresh_dir("repeat");
|
||||
assert!(run_child(&d, "thread").1);
|
||||
assert!(!run_child(&d, "thread_dies").1, "the child aborted");
|
||||
assert!(run_child(&d, "none").1);
|
||||
let (s, _) = only_report(&d);
|
||||
assert_eq!(s.kind, "panic");
|
||||
assert_eq!(s.count, 2);
|
||||
// A repeat the app survives is counted once, though it then ends cleanly.
|
||||
assert!(run_child(&d, "thread").1);
|
||||
assert_eq!(only_report(&d).0.count, 3);
|
||||
let _ = fs::remove_dir_all(&d);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_abort_is_reported_at_the_next_start_with_a_replay() {
|
||||
let d = fresh_dir("abort");
|
||||
|
||||
Reference in New Issue
Block a user