From 629c942d4b78128abbfd1e9c6ffb500e58bc3b6e Mon Sep 17 00:00:00 2001 From: Xuewei Niu Date: Thu, 17 Jul 2025 20:05:56 +0800 Subject: [PATCH] runtime-rs: Fix the issue of blocking socket with Tokio According to the issue [1], Tokio will panic when we are giving a blocking socket to Tokio's `from_std()` method, the information is as follows: ``` A panic occurred at crates/agent/src/sock/vsock.rs:59: Registering a blocking socket with the tokio runtime is unsupported. If you wish to do anyways, please add `--cfg tokio_allow_from_blocking_fd` to your RUSTFLAGS. ``` A workaround is to set the socket to non-blocking. 1: https://github.com/tokio-rs/tokio/issues/7172 Signed-off-by: Xuewei Niu --- src/runtime-rs/crates/agent/src/sock/vsock.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/runtime-rs/crates/agent/src/sock/vsock.rs b/src/runtime-rs/crates/agent/src/sock/vsock.rs index 2612d8133..be04d62c7 100644 --- a/src/runtime-rs/crates/agent/src/sock/vsock.rs +++ b/src/runtime-rs/crates/agent/src/sock/vsock.rs @@ -55,6 +55,15 @@ impl Sock for Vsock { connect(socket.as_raw_fd(), &sock_addr) .with_context(|| format!("failed to connect to {}", sock_addr))?; + // Started from tokio v1.44.0+, it would panic when giving + // `from_std()` a blocking socket. A workaround is to set the + // socket to non-blocking, see [1]. + // + // https://github.com/tokio-rs/tokio/issues/7172 + socket + .set_nonblocking(true) + .context("failed to set non-blocking")?; + // Finally, convert the std UnixSocket to tokio's UnixSocket. UnixStream::from_std(socket).context("from_std") };