fix(netwatch): guard divide-by-zero in poll_recv_noq trace when stride == 0#149
Merged
flub merged 1 commit intoMay 19, 2026
Merged
Conversation
`UdpSocket::poll_recv_noq` evaluated `meta.len / meta.stride` directly inside `trace!()` macro arguments. `noq_udp::RecvMeta.stride` is allowed to be `0` in practice on the GRO path (empty datagrams, kernel falling back to a non-segmented receive), which crashes the host process with `attempt to divide by zero` — observed on Windows 11 24H2 and macOS 15.4/26.x against netwatch 0.16.0/0.17.0. Replace the bare division with `checked_div(...).unwrap_or(0)` so the trace field reports `0` when `stride == 0` and stays identical otherwise. Closes n0-computer#148.
b138431 to
46600c3
Compare
flub
approved these changes
May 19, 2026
Contributor
|
ugh, no checks were required so github merged this immediately and then all CI fails because the commit is no longer there as it was squash-merged 😭 anyway, should be fine. thanks for the PR! |
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.
Description
netwatch::udp::UdpSocket::poll_recv_noqevaluatesmeta.len / meta.stridedirectly insidetrace!()macro arguments.noq_udp::RecvMeta.strideis allowed to be0in practice on the GRO path (empty datagrams, kernel falling back to a non-segmented receive), which makes the trace argument panic withattempt to divide by zeroand terminate the host process — the panic originates inside a tokio task with no upstream catch.This PR replaces the bare division with
checked_div(...).unwrap_or(0), behavior-preserving for all non-zero strides (the only case currently observable) and emittingcount = 0when stride is0.Observed in production on:
across 6 distinct fatal events since 2026-05-12. Same code path is present on
mainand in published0.16.0/0.17.0.Closes #148.
Breaking Changes
None. The new expression is identical to the original for any
stride > 0. Whenstride == 0the field now reports0instead of panicking.Notes & open questions
noq_udp::RecvMeta::stridedoes not forbidstride == 0, so guarding here looks correct regardless of whether the upstreamnoq-udp/ kernel behaviour is intentional.trace!()field, and reproducingstride == 0requires either kernel/GRO state or a mockednoq_udp::State::recv. Happy to add one if a maintainer prefers; otherwise the simpler patch seemed appropriate.Change checklist