From 560d3445f37d0a18b5d122ab28c8e41f7d348bf5 Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Mon, 21 Apr 2025 12:31:20 +0200 Subject: [PATCH] imageproxy: make ImageProxy: Send + Sync The internal detail of how we handle the exit of the child process leads to the entire ImageProxy struct not being Send, which means that it can't be used in cross-thread Futures with tokio. Fortunately it's a very simple fix. Add some trivial static testing to make sure this doesn't regress. Add it for OpenedImage as well: it's currently trivially Send+Sync on account of being a wrapper around an integer, but this might change in the future. This change has been cross-checked against both bootc (ostree-ext) and composefs-rs and doesn't cause any issues. Signed-off-by: Allison Karlitskaya --- src/imageproxy.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/imageproxy.rs b/src/imageproxy.rs index bd6b2f6..f9243d9 100644 --- a/src/imageproxy.rs +++ b/src/imageproxy.rs @@ -132,7 +132,10 @@ struct Reply { } type ChildFuture = Pin< - Box, JoinError>>>, + Box< + dyn Future, JoinError>> + + Send, + >, >; /// Manage a child process proxy to fetch container images. @@ -718,4 +721,20 @@ mod tests { Err(e) => panic!("Unexpected error {e}"), } } + + #[tokio::test] + async fn test_proxy_send_sync() { + fn assert_send_sync(_x: impl Send + Sync) {} + + let Ok(proxy) = ImageProxy::new().await else { + // doesn't matter: we only actually care to test if this compiles + return; + }; + assert_send_sync(&proxy); + assert_send_sync(proxy); + + let opened = OpenedImage(0); + assert_send_sync(&opened); + assert_send_sync(opened); + } }