fix(p2p): use per-connection context in HandleWebSocket#774
Merged
ordishs merged 2 commits intoMay 13, 2026
Conversation
Contributor
|
🤖 Claude Code Review Status: Complete Current Review: This is a well-crafted security fix that correctly addresses a critical DoS vulnerability. The PR demonstrates careful engineering with minimal changes, comprehensive test coverage, and clear documentation. Summary: No issues found. The fix correctly isolates per-connection contexts, preventing upgrade failures from terminating the shared notification processor. The regression test validates the fix effectively. Strengths:
|
Contributor
Benchmark Comparison ReportBaseline: Current: Summary
All benchmark results (sec/op)
Threshold: >10% with p < 0.05 | Generated: 2026-05-12 15:13 UTC |
|
liam
approved these changes
May 13, 2026
gokutheengineer
approved these changes
May 13, 2026
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.



Closes #4573.
Summary
HandleWebSocketcreated a singlectx, cancelpair at server setup and shared it across every WebSocket connection. A single failed upgrade (malformed headers, etc.) calledcancel(), killing the notification processor for ALL connected clients. Severity HIGH because any peer can trigger it remotely.Fix
connCtx, connCancel := context.WithCancel(serverCtx);defer connCancel()cleans up on handler return.s.gCtx(the lifecycle context passed intoNewServer), so the notification processor stops on server shutdown without leaking the goroutine.Test plan
TestHandleWebSocket_PerConnectionContext: drives an upgrade failure on one connection, then connects a real WebSocket client and asserts a notification is still delivered. Fails pre-fix (processor goroutine has exited; client gets EOF), passes post-fix.go test -race ./services/p2p/...passes.