fix(beacon): add per-source relay rate limit to prevent queue monopolization (PILOT-306)#17
Open
matthew-pilot wants to merge 1 commit into
Open
fix(beacon): add per-source relay rate limit to prevent queue monopolization (PILOT-306)#17matthew-pilot wants to merge 1 commit into
matthew-pilot wants to merge 1 commit into
Conversation
…ization (PILOT-306) dispatchRelay has no per-source budget — a malicious sender flooding relays to a known destination can saturate the 524288-deep relayCh and cause queue-full drops for legitimate traffic (SEC-037). Add a per-source sliding-window rate limiter (max 1000 relays/sec) with periodic cleanup in reapStaleNodes. The cap is generous enough that legitimate multi-agent NAT sources won't hit it, but a DoS source can no longer consume the entire queue. Follows the same pattern as the punch-request rate limiter (SEC-026). Closes PILOT-306
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Collaborator
Author
📊 PR Status — #17 PILOT-306
CI Checks (2/2 passing)
Created2026-05-30 20:07 UTC |
Collaborator
Author
🔍 PR Explanation — #17 PILOT-306What this doesAdds a per-source relay rate limit to the beacon server to prevent one sender from monopolizing the relay queue. The problemThe beacon relay queue ( The fix1. New per-source sliding window (
2. Rate cap: 1000 relays/sec per source
3. Cleanup sweep
Files changed
|
Collaborator
Author
|
Status (auto)
|
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.
What
Adds a per-source sliding-window rate limiter to
dispatchRelaythat caps each sender at 1000 relays/second.Why
dispatchRelaycurrently pushes all relay jobs onto a single 524288-deeprelayChchannel with no per-source budget. A malicious sender flooding relays to a known destination can saturate the queue and causerelayDropped— squeezing out legitimate traffic.Fix
relaySourceWindowstruct tracks per-source relay count in 1-second windowsServerstruct:relayRateMu+relaySourceCount map[uint32]*relaySourceWindowdispatchRelayafter the destination pre-check, before buffer allocation and channel enqueuereapStaleNodesVerification
go build ./...— cleango vet ./...— cleango test ./...— relay dispatch tests pass consistently (DispatchRelay_*); pre-existing flaky tests in the parallel UDP suite occur at the same rate on mainScope
1 file, server.go, +38 code lines (+54 including comments).
Closes PILOT-306