diff --git a/crates/socket-patch-cli/src/commands/scan/hosted.rs b/crates/socket-patch-cli/src/commands/scan/hosted.rs index 19759632a..40a94ae94 100644 --- a/crates/socket-patch-cli/src/commands/scan/hosted.rs +++ b/crates/socket-patch-cli/src/commands/scan/hosted.rs @@ -1218,7 +1218,7 @@ pub(super) async fn run_redirect( .iter() .map(|r| (r.writer.purl.clone(), r.writer.uuid.clone())) .collect(); - run_redirect_selected( + boxed_run_redirect_selected( &args.common, &args.vex, prune, diff --git a/crates/socket-patch-cli/src/commands/scan/mod.rs b/crates/socket-patch-cli/src/commands/scan/mod.rs index c1d29b6d9..41fcf0150 100644 --- a/crates/socket-patch-cli/src/commands/scan/mod.rs +++ b/crates/socket-patch-cli/src/commands/scan/mod.rs @@ -34,8 +34,8 @@ use std::path::{Path, PathBuf}; use crate::args::{apply_env_toggles, GlobalArgs}; use crate::commands::vex::{generate_vex_from_manifest_path, VexEmbedArgs}; use crate::ecosystem_dispatch::{ - crawl_ecosystems_with_npm, crawl_ecosystems_with_npm_roots, find_package_paths_for_path_scope, - partition_purls, + boxed, crawl_ecosystems_with_npm, crawl_ecosystems_with_npm_roots, + find_package_paths_for_path_scope, partition_purls, }; use crate::json_envelope::{ usage_error, Command as JsonCommand, Envelope, EnvelopeError, PatchAction, PatchEvent, @@ -2173,15 +2173,10 @@ async fn run_scan( report: &mut report::Run, ) -> i32 { let mut unchecked = 0usize; - let code = Box::pin(scan_project( - args, - invocation, - explicit, - ahead, - &mut unchecked, - report, - )) - .await; + // Built by `boxed`, not by a `Box::pin` here, which would make the + // future of a whole scan a temporary of this frame first. + let code = + boxed(|| scan_project(args, invocation, explicit, ahead, &mut unchecked, report)).await; if unchecked > 0 && code == 0 { 1 } else { @@ -3676,21 +3671,26 @@ async fn scan_project( if let Some(sweep) = withdrawn_sweep { sweep.record_into(&mut env); } - return run_redirect( - &args, - &api_client, - &all_packages_with_patches, - can_access_paid_patches, - &policy, - env, - npm_crawl.as_ref(), - &recorded, - lookup_incomplete, - &mut stage, - prior_discovery, - sweep_references, - prune, - ) + // The hosted flow's future embeds the whole hosted engine: + // awaited in line it lay in the poll frame of a scan in every + // mode. `boxed` leaves this frame one pointer. + return boxed(|| { + run_redirect( + &args, + &api_client, + &all_packages_with_patches, + can_access_paid_patches, + &policy, + env, + npm_crawl.as_ref(), + &recorded, + lookup_incomplete, + &mut stage, + prior_discovery, + sweep_references, + prune, + ) + }) .await; } diff --git a/crates/socket-patch-cli/src/ecosystem_dispatch.rs b/crates/socket-patch-cli/src/ecosystem_dispatch.rs index 7d7f510d4..e5c28f452 100644 --- a/crates/socket-patch-cli/src/ecosystem_dispatch.rs +++ b/crates/socket-patch-cli/src/ecosystem_dispatch.rs @@ -1536,7 +1536,15 @@ impl JvmScope { /// Box the future `make` returns, constructing it inside this (non-async) /// frame so the caller's poll frame only ever holds the pointer. -fn boxed<'a, T, F, Fut>(make: F) -> std::pin::Pin + 'a>> +/// +/// `Box::pin(big(..))` written in an async fn builds the future as a +/// temporary in that fn's poll frame first, and a debug build keeps the +/// room for it. Here the temporary is in a frame that is gone before +/// anything is polled: never inlined, or it would be the caller's again. +#[inline(never)] +pub(crate) fn boxed<'a, T, F, Fut>( + make: F, +) -> std::pin::Pin + 'a>> where F: FnOnce() -> Fut, Fut: std::future::Future + 'a,