Skip to content

fix(udp): handle receive errors before truncation flags in recv_single - #884

Merged
flub merged 2 commits into
mainfrom
rklaehn/fix-recv-single-trunc-spin
Nov 4, 2026
Merged

flub merged 2 commits into
mainfrom
rklaehn/fix-recv-single-trunc-spin

Conversation

@rklaehn

@rklaehn rklaehn commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #883.

Notes & open questions

These are just two cherry-picks. Still needs review from somebody familiar with the context.

Verified that recv_single_after_truncation_returns_would_block_instead_of_spin fails without the fix (macOS).

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All API changes documented.
  • This PR was created by a human that thought critically about the
    proposed change and wrote an as clear and concise description as
    they could.
  • This PR isn't slop, and is carefully crafted to do have the
    intented effect.
  • cargo make passes locally.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/noq/pr/884/docs/noq/

Last updated: 2026-11-04T16:46:46Z

@rklaehn
rklaehn requested a review from flub November 4, 2026 09:39
@n0bot n0bot Bot added this to iroh Nov 4, 2026
@github-project-automation github-project-automation Bot moved this to 🚑 Needs Triage in iroh Nov 4, 2026
zerox80 and others added 2 commits November 4, 2026 18:41
(cherry picked from commit 462865a6c33039c26076f7077c7cd7e2f997b9cd)
(cherry picked from commit f2b3d32c059122e72370b55e091801d19aed676c)
@rklaehn
rklaehn force-pushed the rklaehn/fix-recv-single-trunc-spin branch from 57fc23f to 246ea3f Compare November 4, 2026 16:41
@flub
flub enabled auto-merge November 4, 2026 16:55
@flub
flub added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit 04807b6 Nov 4, 2026
63 of 64 checks passed
@flub
flub deleted the rklaehn/fix-recv-single-trunc-spin branch November 4, 2026 17:05
@github-project-automation github-project-automation Bot moved this from 🚑 Needs Triage to ✅ Done in iroh Nov 4, 2026
caiogondim pushed a commit to agent-habilis/noq that referenced this pull request Nov 20, 2026
n0-computer#884)

## Description

Fixes n0-computer#883.

## Notes & open questions

These are just two cherry-picks. Still needs review from somebody
familiar with the context.

Verified that
`recv_single_after_truncation_returns_would_block_instead_of_spin` fails
without the fix (macOS).

## Change checklist

- [x] Self-review.
- [ ] ~~Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.~~
- [x] Tests if relevant.
- [ ] ~~All API changes documented.~~
- [x] This PR was created by a human that thought critically about the
      proposed change and wrote an as clear and concise description as
      they could.
- [x] This PR isn't slop, and is carefully crafted to do have the
      intented effect.
- [x] `cargo make` passes locally.

---------

Co-authored-by: zerox80 <[email protected]>
Co-authored-by: Dirkjan Ochtman <[email protected]>
(cherry picked from commit 04807b6)
emrul added a commit to GetAster/noq that referenced this pull request Nov 24, 2026
* upstream/main: (24 commits)
  refactor(proto): call the std-only float math through crate-root helpers (n0-computer#848)
  refactor(proto): Avoid PathId allocation when building PATH_ACKS (n0-computer#901)
  chore: Release
  chore(deps): fix unused crates warnings of rust 1.100 (n0-computer#899)
  chore: Update issue template checkboxes (n0-computer#897)
  chore: humantime is unmaintained (n0-computer#900)
  chore(ci): fix workflows for test binaries locations (n0-computer#896)
  fix(perf): don't enable qlog feature in perf binary (n0-computer#850)
  fix(proto): track the key update boundary per path (n0-computer#869)
  tests: additional stream affinity tests (n0-computer#890)
  feat: allow streams to set an affinity for a path, simple version (n0-computer#881)
  fix(udp): handle receive errors before truncation flags in recv_single (n0-computer#884)
  chore: Upgrade async-executor and allow warnings in patchbay build (n0-computer#888)
  chore: Use shared minimal-crates worksflow (n0-computer#862)
  tests: Increase local slow-tests timeout (n0-computer#860)
  fix(proto): keep unread data when compacting an unordered stream (n0-computer#867)
  fix(proto): coalesce contiguous chunks during defragment (n0-computer#866)
  deps: Bump tokio for RUSTSEC-2026-0386 (n0-computer#868)
  feat(proto): Implement `noq_proto::SendStream::set_affinity` (n0-computer#836)
  fix(ci): bump deps for illumos (n0-computer#856)
  ...
CommaBot added a commit to AFK-surf/monoid that referenced this pull request Nov 26, 2026
Backport n0-computer/noq#884 (GHSA-6pp4-4cxf-xf88) into vendor/noq-udp.
On Apple platforms, UdpSocketState defaults to recv_single. That function
set up msghdr once outside the receive loop and checked MSG_TRUNC before
errors. After one UDP datagram larger than the receive buffer (1472 bytes
by default in noq-proto), later EAGAIN errors left MSG_TRUNC set. The
receive thread then spun at 100% CPU while holding the endpoint mutex.

- Reset msghdr via prepare_recv on every attempt inside
  retry_if_interrupted and check errors before MSG_TRUNC.
- Map a zero-byte nameless EOF (SS_CANTRCVMORE) in recv_single and
  recv_via_recvmsg_x to WouldBlock instead of reading uninitialized
  sockaddr_storage or returning Ok(0).
- Add unit and endpoint regression tests in vendor/noq-udp and
  station/native/mesh.
- Document the vendored patch in vendor/README.md.

Changelog: 修复:Apple 设备(macOS / iOS)收到超长 UDP 数据包后,mesh 收包线程在 noq-udp 中空转死循环导致严重发热与断连的问题
Changelog-parts: station, desktop
Co-authored-by: Zhijian Xu <[email protected]>
CommaBot added a commit to AFK-surf/monoid that referenced this pull request Nov 26, 2026
Backport n0-computer/noq#884 (GHSA-6pp4-4cxf-xf88) into vendor/noq-udp.
On Apple platforms, UdpSocketState defaults to recv_single. That function
set up msghdr once outside the receive loop and checked MSG_TRUNC before
errors. After one UDP datagram larger than the receive buffer (1472 bytes
by default in noq-proto), later EAGAIN errors left MSG_TRUNC set. The
receive thread then spun at 100% CPU while holding the endpoint mutex.

- Reset msghdr via prepare_recv on every attempt inside
  retry_if_interrupted and check errors before MSG_TRUNC.
- Map a zero-byte nameless EOF (SS_CANTRCVMORE) in recv_single and
  recv_via_recvmsg_x to WouldBlock instead of reading uninitialized
  sockaddr_storage or returning Ok(0).
- Add unit and endpoint regression tests in vendor/noq-udp and
  station/native/mesh.
- Document the vendored patch in vendor/README.md.

Changelog: 修复:Apple 设备(macOS / iOS)收到超长 UDP 数据包后,mesh 收包线程在 noq-udp 中空转死循环导致严重发热与断连的问题
Changelog-parts: station, desktop
Co-authored-by: Zhijian Xu <[email protected]>
CommaBot added a commit to AFK-surf/monoid that referenced this pull request Nov 26, 2026
…ms (#8897)

Backport n0-computer/noq#884 (GHSA-6pp4-4cxf-xf88) into vendor/noq-udp.
On Apple platforms, UdpSocketState defaults to recv_single. That function
set up msghdr once outside the receive loop and checked MSG_TRUNC before
errors. After one UDP datagram larger than the receive buffer (1472 bytes
by default in noq-proto), later EAGAIN errors left MSG_TRUNC set. The
receive thread then spun at 100% CPU while holding the endpoint mutex.

- Reset msghdr via prepare_recv on every attempt inside
  retry_if_interrupted and check errors before MSG_TRUNC.
- Map a zero-byte nameless EOF (SS_CANTRCVMORE) in recv_single and
  recv_via_recvmsg_x to WouldBlock instead of reading uninitialized
  sockaddr_storage or returning Ok(0).
- Add unit and endpoint regression tests in vendor/noq-udp and
  station/native/mesh.
- Document the vendored patch in vendor/README.md.

Changelog: 修复:Apple 设备(macOS / iOS)收到超长 UDP 数据包后,mesh 收包线程在 noq-udp 中空转死循环导致严重发热与断连的问题
Changelog-parts: station, desktop

Co-authored-by: Zhijian Xu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

noq-udp: recv_single busy-loops after a truncated datagram

4 participants