Skip to content

acceptWith: keep to the give-up when another waiter takes the connection - #662

Merged
kazu-yamamoto merged 3 commits into
haskell:masterfrom
kazu-yamamoto:accept-with-giveup
Nov 22, 2026
Merged

kazu-yamamoto merged 3 commits into
haskell:masterfrom
kazu-yamamoto:accept-with-giveup

Conversation

@kazu-yamamoto

Copy link
Copy Markdown
Collaborator

When several threads wait on one listening socket with acceptWith, one connection wakes them all. The ones which lose the race met EAGAIN inside accept and waited there for the next connection, where the give-up could not reach them. That broke the documented "whichever settles first decides".

  • acceptWith now tries a non-blocking accept (the internal acceptNoWait) once the socket is readable. If the connection is gone, it waits again under the give-up.
  • accept and the public API are unchanged.
  • On Windows, accept is a non-blocking accept behind an AFD poll, so the same fix applies.
  • New test: two threads in acceptWith on one listener, one connection. The thread which loses must return Left once its give-up fires. It fails before the fix.
  • Tested on macOS, Rocky Linux (accept4) and Windows (GHC 9.12.5-rc4, WinIO).

A second commit silences two test warnings which appear only on Windows.

🤖 Generated with Claude Code

kazu-yamamoto and others added 3 commits November 22, 2026 11:33
All the waiters on a listening socket wake for one connection.  The
others met EAGAIN inside accept and waited there, out of reach of the
give-up.  Now acceptWith tries a non-blocking accept once and, if the
connection is gone, waits again under the give-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant