diff --git a/crates/socket-patch-cli/src/ecosystem_dispatch.rs b/crates/socket-patch-cli/src/ecosystem_dispatch.rs index e5c28f452..1d8ee51a5 100644 --- a/crates/socket-patch-cli/src/ecosystem_dispatch.rs +++ b/crates/socket-patch-cli/src/ecosystem_dispatch.rs @@ -1541,6 +1541,10 @@ impl JvmScope { /// 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. +/// +/// The core crate has the same helper for the patch engines +/// (`patch::apply::boxed`), with a `Send` bound this one does not need; +/// keep the two in step. #[inline(never)] pub(crate) fn boxed<'a, T, F, Fut>( make: F, diff --git a/crates/socket-patch-core/src/patch/apply.rs b/crates/socket-patch-core/src/patch/apply.rs index f1f1a7f88..77db17f20 100644 --- a/crates/socket-patch-core/src/patch/apply.rs +++ b/crates/socket-patch-core/src/patch/apply.rs @@ -771,6 +771,32 @@ struct FileOp { saved: Option, } +/// Box the future `make` returns, built in this (non-async) frame so that +/// the caller's poll frame holds only the pointer. +/// +/// A debug build keeps room in an `async fn`'s poll frame for every future +/// it awaits inline, in every branch, and `Box::pin(big(..))` written there +/// builds the future in that frame first. The patch engines sit deep in the +/// call chain of `apply`, `rollback` and `remove`, and the whole chain has +/// to fit the stack of the thread it runs on (2 MiB for a test's). Here the +/// temporary is in a frame that is gone before anything is polled: never +/// inlined, or it would be the caller's again. +/// +/// The CLI has the same helper for its command frames +/// (`ecosystem_dispatch::boxed`), without the `Send` bound: this one keeps +/// the engines' futures `Send`, as they were before they were boxed. Keep +/// the two in step. +#[inline(never)] +pub(crate) fn boxed<'a, T, F, Fut>( + make: F, +) -> std::pin::Pin + Send + 'a>> +where + F: FnOnce() -> Fut, + Fut: std::future::Future + Send + 'a, +{ + Box::pin(make()) +} + /// The sibling name an original is kept under during a [`PackageWrite`]. const SAVED_PREFIX: &str = ".socket-orig-"; @@ -1516,8 +1542,12 @@ pub async fn apply_package_patch( dry_run: bool, policy: MismatchPolicy, ) -> ApplyResult { + // One copy's engine runs behind a pointer: its future is the largest + // of the chain, and every caller up to the command would otherwise + // hold room for it in its own poll frame (see `boxed`). crate::patch::store_copies::fan_out(scope, package_key, pkg_path, |path| async move { - apply_package_patch_at(scope, package_key, &path, files, sources, dry_run, policy).await + boxed(|| apply_package_patch_at(scope, package_key, &path, files, sources, dry_run, policy)) + .await }) .await } diff --git a/crates/socket-patch-core/src/patch/rollback.rs b/crates/socket-patch-core/src/patch/rollback.rs index d1756e3e6..c3fbdc097 100644 --- a/crates/socket-patch-core/src/patch/rollback.rs +++ b/crates/socket-patch-core/src/patch/rollback.rs @@ -394,8 +394,13 @@ pub async fn rollback_package_patch( blobs_path: &Path, dry_run: bool, ) -> RollbackResult { + // One copy's engine runs behind a pointer, as apply's does (see + // `apply::boxed`). crate::patch::store_copies::fan_out(scope, package_key, pkg_path, |path| async move { - rollback_package_patch_at(scope, package_key, &path, files, blobs_path, dry_run).await + crate::patch::apply::boxed(|| { + rollback_package_patch_at(scope, package_key, &path, files, blobs_path, dry_run) + }) + .await }) .await } @@ -432,8 +437,10 @@ pub async fn rollback_store_copies_holding_patch( if !holds_this_patch(©, files).await { continue; } - let copy_result = - rollback_package_patch_at(scope, package_key, ©, files, blobs_path, dry_run).await; + let copy_result = crate::patch::apply::boxed(|| { + rollback_package_patch_at(scope, package_key, ©, files, blobs_path, dry_run) + }) + .await; let result = folded.get_or_insert_with(|| RollbackResult { package_key: package_key.to_string(), package_path: pkg_path.display().to_string(),