Skip to content

Report pending UDP errors before read shutdown - #1916

Merged
Weidong Cui (wdcui) merged 7 commits into
uliteboxfrom
jayb/cherry-pick-race-fix-review
Nov 18, 2026
Merged

Weidong Cui (wdcui) merged 7 commits into
uliteboxfrom
jayb/cherry-pick-race-fix-review

Conversation

@jaybosamiya-ms

@jaybosamiya-ms Jay Bosamiya (Microsoft) (jaybosamiya-ms) commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

This PR makes UDP receives report pending errors, such as ConnectionRefused, before returning Shutdown, even when multiple readers race or a reconnect is in progress. On read shutdown, smoltcp also discards unread datagrams and releases their shared buffer space. Write-only shutdown leaves the receive queue intact.

@jaybosamiya-ms Jay Bosamiya (Microsoft) (jaybosamiya-ms) added the expmt:skipping-stone Tag to quickly find the different PRs as part of the "skipping stone" experiment. label Nov 18, 2026
@jaybosamiya-ms
Jay Bosamiya (Microsoft) (jaybosamiya-ms) marked this pull request as ready for review November 18, 2026 04:08
@jaybosamiya-ms

Jay Bosamiya (Microsoft) (jaybosamiya-ms) commented Nov 18, 2026 •

Copy link
Copy Markdown
Member Author

Weidong Cui (@wdcui) marking you as reviewer since you were looking at UDP stuff recently including some flaky tests. I have not dived into too much detail, but I hit a few flakes with current UDP tests, so asked an agent to figure out why.

As far as I understand, the shutdown fast-path triggered too early, so a pending error might get skipped. Linux reports a pending error before a read-shutdown result, and this PR fixes our ordering, keeping the fast-path, but checking for pending first.

I think the patch is right, but am not fully sure atm. If it seems good to you, please mark for merging, thanks!

@jaybosamiya-ms

Copy link
Copy Markdown
Member Author

Relevant #1891

@wdcui Weidong Cui (wdcui) changed the title Check pending UDP errors before honoring read shutdown Report pending UDP errors before read shutdown Nov 18, 2026
Report read shutdown explicitly from both datagram transports. Whether shutdown is observed by the broker or by an in-flight receive, consume the pending error before returning Shutdown. Exercise both reads before the broker records shutdown.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 05c9f742-0af3-43e5-9b58-8334dcb259d4
A read-shut socket still needs to consume transport errors during a concurrent configuration change. Queue any observed error but do not apply the transitional peer or address snapshot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 05c9f742-0af3-43e5-9b58-8334dcb259d4
Hold the existing per-socket error-query lock across the queue check, claim, and refill. Two racing receives on a read-shut UDP socket must each claim a pending error before either may report shutdown.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 05c9f742-0af3-43e5-9b58-8334dcb259d4
Once the smoltcp receiver stops delivering datagrams, return their bytes to the shared stack budget without clearing pending errors. Leave the queue intact on write-only shutdown.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 05c9f742-0af3-43e5-9b58-8334dcb259d4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 05c9f742-0af3-43e5-9b58-8334dcb259d4
Observe the latched read-shutdown flag and transport retirement in the same socket snapshot. A receive that resumes after both transitions now checks pending errors before reporting shutdown instead of returning NotConnected.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 05c9f742-0af3-43e5-9b58-8334dcb259d4
@github-actions

Copy link
Copy Markdown

🤖 SemverChecks 🤖 No breaking API changes detected

Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered.

@wdcui
Weidong Cui (wdcui) added this pull request to the merge queue Nov 18, 2026
Merged via the queue into ulitebox with commit 78aa2ad Nov 18, 2026
11 checks passed
@wdcui
Weidong Cui (wdcui) deleted the jayb/cherry-pick-race-fix-review branch November 18, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

expmt:skipping-stone Tag to quickly find the different PRs as part of the "skipping stone" experiment.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants