Skip to content

Fix two Linux net bugs that stalled Elixir's Mix: fresh UDP sockets, and a missed epoll rearm - #361

Merged
progrium merged 2 commits into
mainfrom
claude/project-thread-kswdn5
Nov 28, 2026
Merged

progrium merged 2 commits into
mainfrom
claude/project-thread-kswdn5

Conversation

@progrium

Copy link
Copy Markdown
Owner

Requested by Jeff · project thread

Found running real-world programs through h9x on the sud engine: mix local.hex (Elixir 1.15, OTP 26, as elixir-plug/plug builds) timed out after 60 seconds in about one run in three, where it takes 4 seconds natively. Bug fixes, so no proposal.

  • linux: epoll_wait could sleep through an EPOLL_CTL_MOD that rearmed a oneshot entry. It copied the interest list and only then took the readiness generation it sleeps on, so a rearm from another thread between the two was counted in that generation while the copy still had the entry disarmed. The wait slept with the fd ready until something else woke it. Erlang's poll thread waits this way while its schedulers rearm each socket after a read, so a TLS download stopped partway. The generation is now taken before the copy.
  • linux: a fresh UDP socket polled readable and read ENOTCONN. A datagram conversation has no host socket until it binds to a port, connects, or sends, and until then ipready gave the default (readable and writable) and recvfrom gave ENOTCONN. Erlang's resolver logged {udp_error, Port, enotconn}. It's now writable only, a nonblocking recv is EAGAIN, and creating the host socket kicks the watchers, so a recv that blocked before it existed wakes for the reply.

New [linux-net] cases: epoll_rearm (loopback connections read a segment at a time with a rearm after each, as Erlang's TLS does) and udp_fresh. spec/abi-linux.md says both.


Generated by Claude Code

…TCONN

A datagram conversation has no host socket until it binds to a port,
connects, or sends. Until then ipready answered with the default (ready
to read and write) and recvfrom with ENOTCONN, so a poll on a fresh UDP
socket said it was readable and the read failed. Erlang's resolver
polls its new UDP socket and logged the ENOTCONN as an error
({udp_error, Port, enotconn}) during Mix's Hex fetches. Now it's
writable only and a nonblocking recv is EAGAIN, as on Linux, and
creating the host socket kicks the watchers, so a recv blocked before
the socket existed wakes for the reply to its first sendto.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LLcnT1EGgD3xQKfCsAjjvA
… a rearm isn't missed

An epoll_ctl in another thread changes the interest list and then moves
the readiness generation (pollWake). epoll_wait copied the list and only
then took the generation, from its first poll, so an EPOLL_CTL_MOD that
rearmed an EPOLLONESHOT entry between the two was counted in the
generation the wait slept on while the copy still had the entry
disarmed: the wait slept with the fd ready until something else woke it.
Erlang's poll thread waits that way while its schedulers rearm each
socket after a read, so a TLS download stopped partway and Mix's Hex
fetches timed out after 60 seconds, in about one run in three. The
generation is now taken before the copy.

The new epoll_rearm case reads loopback connections a segment at a time,
rearming after each, and failed 3 of 3 runs before (a connection
readable with no event) and passes 3 of 3 after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LLcnT1EGgD3xQKfCsAjjvA

Copy link
Copy Markdown
Owner Author

Test results on 38a7be5, in a cloud container on the sud engine (no KVM there):

  • zig build test passes.
  • zig build integration -Darch=amd64 -Dengines=sud filtered to [linux and [mounts]: 168 pass, 64 skip, 0 fail.
  • The new epoll_rearm case failed 3 of 3 runs without the sys.zig change ("connection N readable, and no event") and passed 3 of 3 with it. udp_fresh failed without the devip and linuxnet changes and passes with them.
  • mix local.hex --force with OTP 26.2.5 and Elixir 1.15.8 under h9, through an HTTPS proxy: 5 of 5 runs installed Hex in about 4 seconds. Before, 3 runs in a row timed out at 60 seconds.

Still unchecked: KVM, HVF, and WHP, and the 9front cases, since this container has no 9front root. Windows has its own hostsock (hostsock-win32.c), which this doesn't change, but the epoll and UDP code is shared.


Generated by Claude Code

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.

2 participants