macos 27 - unexpected/new errno from BSD socket connect() when pending connections exceed backlog

Please consider the trivial C program attached to this thread. The code creates a socket() and listen()s for connections, but (intentionally) doesn't accept() the connections. The listen() is done using a small backlog (of 1).

This test then does several connect() attempts and expects that the connect() attempts will accumulate in the pending queue and once the queue exceeds the backlog limit, then as specified in man listen:

The backlog parameter defines the maximum length for the queue of pending connections. If a connection request arrives with the queue full, the client may receive an error with an indication of ECONNREFUSED.

then the connect() attempt will receive a ECONNREFUSED. However, in macos 27, such a connect() attempt leads to ECONNRESET (Connection reset by peer) instead of ECONNREFUSED. Is this expected? Experiments show that prior versions of macos were returning a ETIMEDOUT for such connect() attempts. If this new error is expected from connect() when the backlog limit has exceeded, should it be specified in the man listen documentation?

Rename the attached main.c.txt to main.c. Compiling the attached program on macos 27, using clang main.c and then running ./a.out results in:

-----------------------
MacOS version: 27.0.1
Kernel version: Darwin Kernel Version 27.0.0: Tue Aug 11 21:02:16 PDT 2026; root:xnu-13432.1.9~1/RELEASE_ARM64_T8112
-----------------------
started server at at 127.0.0.1:52753 with a backlog of 1
connect() attempt 1 - connected
connect() attempt 2 - connected
connect() attempt 3 - connected
connect() attempt 4 - connected
connect() attempt 5 - failed to connect() - Connection reset by peer <-- FAILURE: Unexpected error code, expected either ETIMEDOUT or ECONNREFUSED but got 54
connect() attempt 6 - connected
connect() attempt 7 - connected
connect() attempt 8 - connected
connect() attempt 9 - failed to connect() - Connection reset by peer <-- FAILURE: Unexpected error code, expected either ETIMEDOUT or ECONNREFUSED but got 54
connect() attempt 10 - failed to connect() - Connection reset by peer <-- FAILURE: Unexpected error code, expected either ETIMEDOUT or ECONNREFUSED but got 54
connect() attempt 11 - failed to connect() - Connection reset by peer <-- FAILURE: Unexpected error code, expected either ETIMEDOUT or ECONNREFUSED but got 54

On a related note, it's unclear why several of the connect() attempts succeeded instead of just 1 of them succeeding. On prior versions of macos, the output of the same program is:

-----------------------
MacOS version: 26.7.1
Kernel version: Darwin Kernel Version 25.6.0: Tue Aug 18 17:49:13 PDT 2026; root:xnu-12377.161.15.700.19~2/RELEASE_ARM64_T6000
-----------------------
started server at at 127.0.0.1:52451 with a backlog of 1
connect() attempt 1 - connected
connect() attempt 2 - failed to connect() - Operation timed out
connect() attempt 3 - failed to connect() - Operation timed out
connect() attempt 4 - failed to connect() - Operation timed out
connect() attempt 5 - failed to connect() - Operation timed out
connect() attempt 6 - failed to connect() - Operation timed out
connect() attempt 7 - failed to connect() - Operation timed out
connect() attempt 8 - failed to connect() - Operation timed out
connect() attempt 9 - failed to connect() - Operation timed out
connect() attempt 10 - failed to connect() - Operation timed out
connect() attempt 11 - failed to connect() - Operation timed out

and this output is much more understandable and deterministic.

Answered by DTS Engineer in 907693022

The discrepancy between the man page and the runtime behaviour is most is most definitely a bug — one or the other needs to change here — and I recommend that you file it as such.

Your second issue also seems like a bug to me, especially given that it’s a change from earlier system. It’d be best for you to file a separate bug report about that.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

The discrepancy between the man page and the runtime behaviour is most is most definitely a bug — one or the other needs to change here — and I recommend that you file it as such.

Your second issue also seems like a bug to me, especially given that it’s a change from earlier system. It’d be best for you to file a separate bug report about that.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The discrepancy between the man page and the runtime behaviour is most is most definitely a bug — one or the other needs to change here — and I recommend that you file it as such.

Thank you Quinn. I've filed FB25031051 for this one.

Your second issue also seems like a bug to me, especially given that it’s a change from earlier system. It’d be best for you to file a separate bug report about that.

Filed a separate FB25031272 for this.

macos 27 - unexpected/new errno from BSD socket connect() when pending connections exceed backlog
 
 
Q