From 90bd20f1436815b1b45ae4dd288a8ab4ff93bedb Mon Sep 17 00:00:00 2001 From: Joas A Santos <34966120+CyberSecurityUP@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:18:42 -0300 Subject: [PATCH] fix(pipeline): keep the run futures Send so the binaries compile again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neither binary has compiled since traffic recording landed. The release binary on disk was three weeks older than the source, which is why. At the end of run(), traffic_record::store() returns a std::sync::MutexGuard that stayed alive across the tx.send(...).await two lines below. A MutexGuard is not Send, so the enclosing future is not Send, and both app/src/main.rs and app/src/tui.rs hand these futures to tokio::spawn, which requires it. The library kept building clean throughout: nothing in it spawns a run, so cargo check -p neurosploit-harness never saw the problem. That is the whole reason this went unnoticed — every check I ran this session was scoped to the library. Scope the guard so it drops before the await. Add a Send assertion over all six run futures. Reverting the scope fix makes it fail with "future cannot be sent between threads safely", so it catches the real thing rather than restating it. Co-Authored-By: Claude Opus 5 --- neurosploit-rs/crates/harness/src/pipeline.rs | 19 ++++++++---- .../crates/harness/src/traffic_record.rs | 29 +++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) 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)); + } +}