Skip to content

Commit 560d344

Browse files
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 <[email protected]>
1 parent 8327958 commit 560d344

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/imageproxy.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ struct Reply {
132132
}
133133

134134
type ChildFuture = Pin<
135-
Box<dyn Future<Output = std::result::Result<std::io::Result<std::process::Output>, JoinError>>>,
135+
Box<
136+
dyn Future<Output = std::result::Result<std::io::Result<std::process::Output>, JoinError>>
137+
+ Send,
138+
>,
136139
>;
137140

138141
/// Manage a child process proxy to fetch container images.
@@ -718,4 +721,20 @@ mod tests {
718721
Err(e) => panic!("Unexpected error {e}"),
719722
}
720723
}
724+
725+
#[tokio::test]
726+
async fn test_proxy_send_sync() {
727+
fn assert_send_sync(_x: impl Send + Sync) {}
728+
729+
let Ok(proxy) = ImageProxy::new().await else {
730+
// doesn't matter: we only actually care to test if this compiles
731+
return;
732+
};
733+
assert_send_sync(&proxy);
734+
assert_send_sync(proxy);
735+
736+
let opened = OpenedImage(0);
737+
assert_send_sync(&opened);
738+
assert_send_sync(opened);
739+
}
721740
}

0 commit comments

Comments
 (0)