Skip to content

Accept unix peers that hang up before accept on macOS - #8766

Merged
littledivy merged 1 commit into
mainfrom
littledivy/2026-11-21-unix-accept-enotconn
Nov 25, 2026
Merged

littledivy merged 1 commit into
mainfrom
littledivy/2026-11-21-unix-accept-enotconn

Conversation

@littledivy

Copy link
Copy Markdown
Member

On macOS, LOCAL_PEERCRED fails with ENOTCONN once the peer has closed, even while the connection is still waiting in the listen backlog. kj-rs-io turned that into an exception, so acceptAuthenticated() on a unix listener failed whenever a client, such as a health probe, connected and hung up before it was accepted. Linux keeps the credentials captured at connect(), so it was not affected.

In this patch a NotConnected error from peer_cred() gives a peer with no pid or uid, and the stream is returned as usual. Its next read reports EOF. Other errors still throw. The new test in async-io-test.c++ fails on macOS without the fix.

Fixes #8122.

macOS fails LOCAL_PEERCRED with ENOTCONN once the peer has closed,
even while the connection still waits in the listen backlog. kj-rs-io
turned that into an exception, so acceptAuthenticated() on a unix
listener failed when a client such as a health probe connected and
hung up before it was accepted. Linux keeps the credentials captured
at connect() and was not affected.

In this patch a NotConnected error from peer_cred() gives a peer with
no pid or uid, and the stream is returned as usual; its next read
reports EOF. Other errors still throw.

Fixes #8122.
@littledivy
littledivy requested review from a team as code owners November 21, 2026 03:00

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — This is a small, correct fix: only NotConnected from peer_cred() is treated as "no credentials" and all other errors still propagate. The new regression test covers it, and I found no issues.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

Only ErrorKind::NotConnected from peer_cred() is treated as "no credentials", and every other error still propagates with the same message as before. The pid and uid follow KJ's validity rules, and a missing uid is now reported as 0 with has_uid false. The test drops the client stream before accept, then checks that the stream reads EOF and that the listener goes on accepting connections.


📝 Documentation: ✅ LGTM

The updated doc comment on peer_credentials and the test comment describe how the code behaves now, which is what the repository's comment guidelines ask for.


Reviewed commit: edf28715

@littledivy
littledivy merged commit 8ab0acf into main Nov 25, 2026
23 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-21-unix-accept-enotconn branch November 25, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: acceptAuthenticated fails with ENOTCONN when a Unix peer disconnects before accept

2 participants