fix(beacon): narrow TOCTOU window in handlePunchRequest (PILOT-339)#13
Conversation
Re-snapshot the target and requester addresses immediately before each SendPunchCommand call to reduce the stale-address window. The underlying race is still possible (no locking across the UDP write) — UDP best-effort absorbs the remaining loss; the daemon retries on timeout. PILOT-339
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
🦭 Matthew PR Check — #13 PILOT-339Status
VerdictCLEAN — all CI green, mergeable, no review conflicts. Small focused fix narrowing TOCTOU window in |
🦭 Matthew Explains — #13 PILOT-339What this doesIn This fix re-snapshots each participant's address immediately before the corresponding Why it's safe
What to look for in review
|
🧹 Matthew Cleanup — #13 MergedPR merged by TeoSlayer at 2026-05-29T20:36:19Z. Cleaning up now.
Thanks for the merge! 🚀 |
✅ Matthew Merged Cleanup — #13 PILOT-339Merged by TeoSlayer at 2026-05-29 20:36 UTC Branch Action: Jira PILOT-339 → READY. The TOCTOU window in handlePunchRequest has been narrowed. UDP best-effort absorbs any remaining race; daemon retries on timeout. |
Summary
PILOT-339: In
handlePunchRequest, the target and requester endpoints are snapshot once and then used forSendPunchCommandafter a delay (the second send). Between the snapshot and the send, the peer may have re-registered from a different NAT binding, causing a TOCTOUstale-address → lost punch → daemon retry.This fix re-snapshots each participant's address immediately before the corresponding
SendPunchCommandcall, narrowing the staleness window significantly. The underlying race remains possible (no locking across the UDP write) — UDP best-effort absorbs the remaining loss; the daemon retries on timeout.Changes
server.go: inline re-snapshot oftargetIDandrequesterIDbefore each send inhandlePunchRequest(+ documentation of the trade-off)Verification
go build,go vet, and relevant tests (TestHandlePunchRequest_*,TestSendPunchCommand_*,TestNodeMap_*) all pass.