Merge nucleic/tidy-north-gecko-6wqv into dev

This commit is contained in:
2026-07-17 15:35:17 -07:00
parent 9de6a6cee7
commit 3168f3d8b6
4 changed files with 212 additions and 27 deletions
@@ -130,6 +130,21 @@ extension Socket {
SocketError.withErrno("\(msg) (\(_errnoString(errno)))", errno: errno)
}
/// [Nucleic vendored patch] Whether an `accept(2)` failure is transient — the listener is still
/// healthy and later accepts can succeed — as opposed to a dead listener. ECONNABORTED/ECONNRESET
/// are a single queued connection dying before accept; EMFILE/ENFILE/ENOBUFS/ENOMEM are resource
/// pressure that clears; EINTR/EAGAIN are spurious wakeups. See `acceptStream`.
static func isTransientAcceptError(_ error: Swift.Error) -> Bool {
guard case SocketError.withErrno(_, let code) = error else { return false }
switch code {
case ECONNABORTED, ECONNRESET, EINTR, EAGAIN, EWOULDBLOCK, EMFILE, ENFILE, ENOBUFS, ENOMEM,
EPROTO:
return true
default:
return false
}
}
public func connect() throws {
try state.withLock { currentState in
guard currentState.socketState == .created else {
@@ -277,6 +292,17 @@ extension Socket {
} catch SocketError.closed {
source.cancel()
} catch {
// [Nucleic vendored patch] One-strike accepting is a control-plane brick: a
// single transient accept(2) failure — ECONNABORTED (peer aborted while queued,
// routine under connection churn), EMFILE/ENFILE (fd pressure), ENOBUFS/ENOMEM,
// EINTR — used to cancel the source FOREVER while the socket stayed bound and
// listening. Every later client then connect(2)ed into the kernel backlog and
// hung unanswered (a silent black hole — the "agent produced no output within
// 60s" stall when this socket is a relayed control plane). Skip the failed
// accept and keep listening; only a genuinely dead listener ends the stream.
if Self.isTransientAcceptError(error) {
return
}
cont.yield(with: .failure(error))
source.cancel()
}