Skip to content

Give PollRegistrations' checks ten seconds for loopback to deliver (#431) - #444

Merged
dimensionscape merged 1 commit into
mainfrom
fix/poll-registrations-loopback-delay
Nov 13, 2026
Merged

dimensionscape merged 1 commit into
mainfrom
fix/poll-registrations-loopback-delay

Conversation

@dimensionscape

@dimensionscape dimensionscape commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

PollRegistrations failed now and then on macOS arm64 (#431): a socket that had been sent bytes wasn't reported readable within the one second each check waited. It turns out the kqueue backend was right, and loopback hadn't delivered the bytes yet.

I ran the test 400 times on a macOS arm64 runner, with every kevent change and result traced and FIONREAD read for each socket after every wait. It failed 3 times the way #431 describes, and in another run once on the UDP check "ready in prepared order". In the failing TCP runs:

  • For all 50 waits, the client's FIONREAD was 0, and kqueue reported it writable only.
  • The server's write filter reported 146,983 bytes free against the client's 146,988, so the 5 bytes of "hello" were still in the server's send buffer. In one run they were still there two seconds later.
  • The blocking read after the checks got them, as the issue saw.

So the delay is in delivery over loopback on the runner, not in Poll. The UDP failure fits too: the datagrams were reported on the next check.

A check now polls until its result matches or ten seconds pass, and so does the Poll.poll check. A check that matches stops at once, as before, so only a failing one waits the whole time. The library is unchanged, so there's no Changes.md line.

With this change I ran the loop twice more, 400 runs each, logging any check that took over half a second. None did, and all 800 runs passed, so those runners never stalled and the loops don't exercise the longer wait. The earlier failures came in 4 of 634 runs, on other runner machines. The traced runs: 43373583292 (3 failures) and 43373029128 (1). With the fix: 43376217521, both attempts.

Fixes #431.

PollRegistrations failed now and then on macOS arm64 runners, a socket
that had been sent bytes not reported readable within the second each
check waited (libhxcpp #431). A traced loop of 400 runs on a runner
failed 3 times this way and once with datagrams, and showed the kqueue
backend was right: for the whole wait the client's FIONREAD was 0 and the
server's write filter reported the 5 bytes still in its send buffer, so
loopback had not delivered them. They arrived later, as the blocking read
after the checks got them.

A check now polls until its result matches or ten seconds pass, so it
stops as soon as it matches and only a failing check waits the whole
time. The library is unchanged.
@dimensionscape
dimensionscape merged commit d32eb02 into main Nov 13, 2026
36 checks passed
@dimensionscape
dimensionscape deleted the fix/poll-registrations-loopback-delay branch November 13, 2026 10:48
@dimensionscape dimensionscape mentioned this pull request Nov 13, 2026
28 of 34 tasks
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.

PollRegistrations sometimes misses a readable socket with kqueue on macOS arm64

1 participant