From b6c13661c2e3d3b60ef010703b07610111d6e2a4 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Thu, 20 Aug 2026 03:01:07 +0800 Subject: [PATCH] Always poll_connect on Apple platforms in connect_timeout On Apple platforms (macOS, iOS, tvOS, watchOS, visionOS) a non-blocking connect(2) can return success even though the connection is not yet established. Treating that as immediate success causes connect_timeout to return Ok(()) while the socket is still unconnected. Skip the fast-path early return on Apple platforms so the function always falls through to poll_connect, which waits for the connection to actually complete. Fixes #652. --- src/socket.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/socket.rs b/src/socket.rs index da01a77a..f6fc9835 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -218,7 +218,20 @@ impl Socket { self.set_nonblocking(false)?; match res { - Ok(()) => return Ok(()), + Ok(()) => { + // On Apple platforms (macOS, iOS, tvOS, watchOS, visionOS) a + // non-blocking `connect(2)` may return success even though the + // connection is not yet established, so we always fall through + // to `poll_connect` to wait for the connection to complete. + #[cfg(not(any( + target_os = "ios", + target_os = "visionos", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + )))] + return Ok(()); + } Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {} #[cfg(any(unix, all(target_os = "wasi", not(target_env = "p1"))))] Err(ref e) if e.raw_os_error() == Some(libc::EINPROGRESS) => {}