Skip to content

Commit 322d0b5

Browse files
committed
fix(extensions): use spawn_blocking for abstract socket connect
connect_addr is a blocking syscall from std that can stall a tokio worker thread if the sidecar is slow to accept. Move it to spawn_blocking so the async runtime stays responsive.
1 parent c1d7153 commit 322d0b5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

crates/goose/src/agents/unix_socket_http_client.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,18 @@ fn resolve_socket_path(raw: &str) -> String {
7474
async fn connect_unix(socket_path: &str) -> Result<UnixStream, std::io::Error> {
7575
#[cfg(target_os = "linux")]
7676
if let Some(abstract_name) = socket_path.strip_prefix('\0') {
77-
use std::os::linux::net::SocketAddrExt;
78-
let addr = std::os::unix::net::SocketAddr::from_abstract_name(abstract_name)?;
79-
// tokio::net::UnixStream has no connect_addr; use std then convert
80-
let std_stream = std::os::unix::net::UnixStream::connect_addr(&addr)?;
81-
std_stream.set_nonblocking(true)?;
77+
// tokio::net::UnixStream has no connect_addr; use std via spawn_blocking
78+
// to avoid blocking a tokio worker thread during the connect syscall
79+
let abstract_name = abstract_name.to_string();
80+
let std_stream = tokio::task::spawn_blocking(move || {
81+
use std::os::linux::net::SocketAddrExt;
82+
let addr = std::os::unix::net::SocketAddr::from_abstract_name(&abstract_name)?;
83+
let stream = std::os::unix::net::UnixStream::connect_addr(&addr)?;
84+
stream.set_nonblocking(true)?;
85+
Ok::<_, std::io::Error>(stream)
86+
})
87+
.await
88+
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))??;
8289
return UnixStream::from_std(std_stream);
8390
}
8491

0 commit comments

Comments
 (0)