Repository navigation
fix(noq): don't stall tokio UDP sends on OpenBSD send lock contention - #4
Merged
Merged
Conversation
OpenBSD fails a non-blocking UDP sendmsg with EAGAIN while another thread holds the socket's send buffer lock: sosend takes it with RW_NOSLEEP under MSG_DONTWAIT, which sendit sets for non-blocking descriptors. The buffer itself never fills for UDP. The tokio runtime's try_send went through try_io, which clears write readiness on WouldBlock, so the sender then waited for a kqueue EVFILT_WRITE event that a UDP socket never raises again (nothing ever drains its send buffer). Every connection sending on that socket stalled for good: an endpoint shared by several connections, or a multipath connection sending on several paths at once, went silent until its connections timed out. On OpenBSD, retry such a send a bounded number of times without touching readiness, and drop the datagram if contention persists, as for other send errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012baC35vUbLPPhuK4pz4uRz
|
Documentation for this PR has been generated and is available at: https://losfair.github.io/noq/pr/4/docs/noq/ Last updated: 2026-10-15T18:06:48Z |
losfair
pushed a commit
to losfair/rapidmasque
that referenced
this pull request
Oct 15, 2026
losfair/noq#4 merged as cad1d3a on dev (same tree as the PR head 2f590c1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012baC35vUbLPPhuK4pz4uRz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On OpenBSD, an endpoint running on the tokio runtime can go permanently silent. Every connection on it stops sending at the same moment, and they all time out later. It receives and handles packets fine, including new Initials, but never answers.
Cause
EAGAINis not a full buffer.senditaddsMSG_DONTWAITfor non-blocking descriptors (sys/kern/uipc_syscalls.c).sosendthen takes the send buffer lock withsblock(&so->so_snd, SBLOCKWAIT(flags)). That doesn't sleep, so it fails withEWOULDBLOCKwhen another thread is insosendon the same socket at the time (sys/kern/uipc_socket.c,uipc_socket2.c).so_snd, so it is always empty. An oversized datagram is rejected withEMSGSIZEbefore that check.try_sendgoes throughtry_io, which clears write readiness onWouldBlock. The sender then waits for kqueue to report the socket writable again, and for a UDP socket that event never comes, because nothing ever drains its send buffer.It's most likely when several connections, or one multipath connection's paths, send at once. One example is a burst of
CONNECTION_CLOSEs on several paths.The smol runtime isn't affected: async-io's readiness wait re-arms the socket, and kqueue reports a UDP socket writable straight away.
Evidence
From rapidmasque's OpenBSD smoke test on x86_64 (KVM) and arm64 (emulated); see losfair/rapidmasque#7.
sendmsg(10, …)calls, one of which returns-1 errno 35 Resource temporarily unavailablewhile the other completes. It was the only failedsendmsgof the run, and after it the server made no furthersendmsgcalls at all.recvmsging a new client's Initials and sending nothing.Fix
On OpenBSD only,
try_sendretries aWouldBlocksend up to 64 times withthread::yield_now(), without touching readiness. If the contention persists, it drops the datagram (Ok(())), asUdpSocketState::sendalready does for other send errors; QUIC recovers the loss. Elsewhere the behaviour is unchanged.Testing
cargo clippy -p noq --all-targets -- -D warningspasses.cargo +nightly check -p noq --no-default-features --features runtime-tokio --target x86_64-unknown-openbsd -Zbuild-std=std,panic_abortpasses with no warnings.cargo test -p noq --lib: 3 tests fail (echo_v6,echo_dualstack,local_addr). They fail identically ondev, because this sandbox has no IPv6.🤖 Generated with Claude Code
https://claude.ai/code/session_012baC35vUbLPPhuK4pz4uRz
Generated by Claude Code