mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-19 16:38:00 +00:00
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 <niuxuewei.nxw@antgroup.com>
This commit is contained in:
parent
1508e6f0f5
commit
629c942d4b
@ -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")
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user