Merge nucleic/tidy-north-gecko-6wqv into dev
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user