From 978c4e8b69a1cde2c449e477de35a497dd0cc506 Mon Sep 17 00:00:00 2001 From: llmII Date: Sat, 13 Dec 2025 16:56:56 -0600 Subject: [PATCH] Fix unix sockets issue on FreeBSD Sometimes a unix socket has a 0 status return which indicates the connection immediately succeeded, at which point entering the event loop waiting on the connection to complete actually breaks things. It seems on FreeBSD with events being edge triggered, we're awaiting a connection to signal it's writeable (to complete the connection) but that never occurs (the event already took place before we registered for the event). Going by status alone to determine if we should enter into the event loop to await the complete connection seems sensible here. --- src/core/net.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/net.c b/src/core/net.c index d6c2240c..f40352e4 100644 --- a/src/core/net.c +++ b/src/core/net.c @@ -572,7 +572,15 @@ JANET_CORE_FN(cfun_net_connect, } #endif - if (status) { + if (status == 0) { + /* Connect completed synchronously (common for unix domain sockets). + * Return the stream directly without scheduling an async wait, + * as edge-triggered kqueue may not signal EVFILT_WRITE if the socket + * is already connected when registered. */ + return janet_wrap_abstract(stream); + } + + if (status == -1) { #ifdef JANET_WINDOWS if (err != WSAEWOULDBLOCK) { #else