From 46221faa635073b5e509e6e4796cd28a3ea64af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Sat, 28 Mar 2026 16:05:00 -0500 Subject: [PATCH] unix,stream: fix getsockopt error handling in connect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: https://github.com/libuv/libuv/issues/5086 Signed-off-by: Juan José Arboleda --- src/unix/stream.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/unix/stream.c b/src/unix/stream.c index 86a179b35..f0590299e 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -1264,12 +1264,15 @@ static void uv__stream_connect(uv_stream_t* stream) { } else { /* Normal situation: we need to get the socket error from the kernel. */ assert(uv__stream_fd(stream) >= 0); - getsockopt(uv__stream_fd(stream), - SOL_SOCKET, - SO_ERROR, - &error, - &errorsize); - error = UV__ERR(error); + if (getsockopt(uv__stream_fd(stream), + SOL_SOCKET, + SO_ERROR, + &error, + &errorsize)) { + error = UV__ERR(errno); + } else { + error = UV__ERR(error); + } } if (error == UV__ERR(EINPROGRESS))