diff --git a/neurosploit-rs/crates/harness/src/pipeline.rs b/neurosploit-rs/crates/harness/src/pipeline.rs index f26a046..2799fc2 100644 --- a/neurosploit-rs/crates/harness/src/pipeline.rs +++ b/neurosploit-rs/crates/harness/src/pipeline.rs @@ -6178,12 +6178,19 @@ async fn finish(cfg: RunConfig, _lib: &Library, pool: &ModelPool, recon: String, // Persist traffic recording if enabled. if crate::traffic_record::enabled() { if let Some(ref wd) = cfg.workdir { - let log = crate::traffic_record::store(); - let json_path = std::path::Path::new(wd).join("traffic.json"); - let _ = crate::traffic_record::save_json(&log, &json_path.to_string_lossy()); - let har_path = std::path::Path::new(wd).join("traffic.har"); - let _ = std::fs::write(&har_path, crate::traffic_record::export_har(&log)); - let summary = log.stats(); + // The guard must not survive into the await below. std::sync's + // MutexGuard is not Send, and holding one across a suspension + // point makes the whole run future non-Send — which tokio::spawn + // requires, so both binaries stop compiling while the library + // still builds clean on its own. + let summary = { + let log = crate::traffic_record::store(); + let json_path = std::path::Path::new(wd).join("traffic.json"); + let _ = crate::traffic_record::save_json(&log, &json_path.to_string_lossy()); + let har_path = std::path::Path::new(wd).join("traffic.har"); + let _ = std::fs::write(&har_path, crate::traffic_record::export_har(&log)); + log.stats() + }; let _ = tx.send(format!("📡 traffic: {} request(s), {} error(s), {} WAF block(s) → traffic.json + traffic.har", summary.total, summary.errors, summary.blocked)).await; } diff --git a/neurosploit-rs/crates/harness/src/traffic_record.rs b/neurosploit-rs/crates/harness/src/traffic_record.rs index e957a14..fb76d50 100644 --- a/neurosploit-rs/crates/harness/src/traffic_record.rs +++ b/neurosploit-rs/crates/harness/src/traffic_record.rs @@ -453,3 +453,32 @@ mod tests { assert!(formatted.contains("2024")); } } + +#[cfg(test)] +mod send_tests { + /// The run futures must stay `Send`, because both binaries hand them to + /// `tokio::spawn`, which requires it. + /// + /// This is easy to break from inside the library and impossible to notice + /// there: holding a `std::sync::MutexGuard` — `traffic_record::store()` + /// returns one — across an `.await` makes the enclosing future non-Send, + /// and `cargo check -p neurosploit-harness` still passes because nothing + /// in the library spawns them. Only the binaries fail, which is how the + /// release binary came to be three weeks older than the source. + #[test] + fn the_run_futures_are_send() { + fn assert_send(_: &T) {} + + let cfg = crate::types::RunConfig::new("example.test"); + let lib = crate::agents::Library::default(); + let pool = crate::pool::ModelPool::new(Vec::new(), 1); + let (tx, _rx) = tokio::sync::mpsc::channel::(1); + + assert_send(&crate::pipeline::run(cfg.clone(), &lib, &pool, tx.clone())); + assert_send(&crate::pipeline::run_whitebox(cfg.clone(), &lib, &pool, tx.clone())); + assert_send(&crate::pipeline::run_greybox(cfg.clone(), &lib, &pool, tx.clone())); + assert_send(&crate::pipeline::run_host(cfg.clone(), &lib, &pool, tx.clone())); + assert_send(&crate::pipeline::run_container(cfg.clone(), &lib, &pool, tx.clone())); + assert_send(&crate::pipeline::run_mobile(cfg, &lib, &pool, tx)); + } +}