From 55458739670061b6f7b02f550015bf31c29d6c9d Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Tue, 13 Oct 2026 10:29:31 +0530 Subject: [PATCH] test(fuzz): retry an interrupted crash copy and report why a copy failed (#564) The nightly ops_sequence run failed with 'step 3: copy failed' after 83k executions; the input passes alone and in 5000 repeats. libFuzzer's -timeout alarm (ITIMER_REAL, no SA_RESTART) can interrupt syscalls, and the message dropped the io::Error. crash_copy now retries Interrupted and names the file and error kind. Adds the input as a corpus seed and as a model-based test. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016QAt9R1aSPQG7rV5ouFDMU --- .../seed_564_repeated_crash_copies.bin | Bin 0 -> 135 bytes tests/model_based_test.rs | 49 ++++++++++++++++++ tests/reference_model/mod.rs | 23 +++++--- 3 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 fuzz/corpus/ops_sequence/seed_564_repeated_crash_copies.bin diff --git a/fuzz/corpus/ops_sequence/seed_564_repeated_crash_copies.bin b/fuzz/corpus/ops_sequence/seed_564_repeated_crash_copies.bin new file mode 100644 index 0000000000000000000000000000000000000000..81e8f7e1106665ead9c4984a50837e3268b68d10 GIT binary patch literal 135 ocmZRIt-AaF|NndjAQ8TS9}n1yM-ELY5fh-PK;riMZSN=q0DwsuJOBUy literal 0 HcmV?d00001 diff --git a/tests/model_based_test.rs b/tests/model_based_test.rs index 3979a6fa63..94ec1b1408 100644 --- a/tests/model_based_test.rs +++ b/tests/model_based_test.rs @@ -104,3 +104,52 @@ proptest! { run(&steps, Checks::All)?; } } + +/// The #564 nightly input: one transact, then a crash copy after every step. +/// Under libFuzzer one copy failed with an unreported error; `crash_copy` now +/// retries `Interrupted` and names the file and error kind. +#[test] +fn repeated_crash_copies_match_model() { + let probe = Probe { + as_of: 0, + at: 3, + e: 3, + a: 0, + v: V::Int(i64::MIN), + pick: 15, + }; + let mut steps = vec![Step { + op: Op::Exec(Stmt::Transact { + window: Window { + vf: None, + vt: Some(3), + }, + facts: vec![FactSpec { + e: 3, + a: 0, + v: V::Int(i64::MIN), + window: Window::default(), + }], + }), + probe: probe.clone(), + }]; + for _ in 0..8 { + steps.push(Step { + op: Op::Crash(OpenMode::Default), + probe: probe.clone(), + }); + } + run(&steps, Checks::All).expect("crash copies match the model"); +} + +/// A failed copy says which file and why. +#[test] +fn crash_copy_names_the_failing_file() { + let dir = tempfile::tempdir().unwrap(); + let missing = dir.path().join("missing.graph"); + let err = crash_copy(&missing, &dir.path().join("to.graph"), 7).unwrap_err(); + let msg = err.to_string(); + assert!(msg.contains("step 7"), "message names the step"); + assert!(msg.contains("database file"), "message names the file"); + assert!(msg.contains("NotFound"), "message carries the error kind"); +} diff --git a/tests/reference_model/mod.rs b/tests/reference_model/mod.rs index 696b7e2d9c..c99a0e0d42 100644 --- a/tests/reference_model/mod.rs +++ b/tests/reference_model/mod.rs @@ -737,20 +737,31 @@ pub fn open(path: &Path, mode: OpenMode) -> Result { /// Copy the database file and its WAL as they are on disk right now. On /// Windows, where locks are mandatory, the caller closes the handle first, /// which turns the step into a plain reopen. +/// +/// `fs::copy` can fail with `Interrupted` under libFuzzer, whose `-timeout` +/// alarm signal is installed without `SA_RESTART`, so the copy retries that. +/// Any other error names the file and the error kind (#564). pub fn crash_copy(from: &Path, to: &Path, step: usize) -> Result<(), TestCaseError> { let wal = |p: &Path| { let mut s = p.as_os_str().to_owned(); s.push(".wal"); std::path::PathBuf::from(s) }; - let copy = |a: &Path, b: &Path| { - std::fs::copy(a, b) - .map(|_| ()) - .map_err(|_| TestCaseError::fail(format!("step {step}: copy failed"))) + let copy = |a: &Path, b: &Path, what: &str| loop { + match std::fs::copy(a, b) { + Ok(_) => return Ok(()), + Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue, + Err(e) => { + return Err(TestCaseError::fail(format!( + "step {step}: copy of the {what} failed ({:?})", + e.kind() + ))); + } + } }; - copy(from, to)?; + copy(from, to, "database file")?; if wal(from).exists() { - copy(&wal(from), &wal(to))?; + copy(&wal(from), &wal(to), "WAL")?; } Ok(()) }