-
Notifications
You must be signed in to change notification settings - Fork 129
fix(guard): fix 1006 when client closes ws connection #3381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(guard): fix 1006 when client closes ws connection #3381
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
c923a6f to
51912f8
Compare
500649f to
4078059
Compare
More templates
@rivetkit/actor
@rivetkit/cloudflare-workers
@rivetkit/core
@rivetkit/db
@rivetkit/framework-base
@rivetkit/next-js
@rivetkit/react
rivetkit
@rivetkit/sql-loader
@rivetkit/engine-runner
@rivetkit/engine-runner-protocol
commit: |
Code ReviewSummaryThis PR fixes WebSocket close code 1006 errors that occur when clients close WebSocket connections. The fix adds proper error handling for close frame send/flush operations and ensures a proper close frame is always sent, even when no explicit close frame is provided. Positive Aspects1. Proper Error Handling
2. Good Logging
3. Graceful Degradation
Issues and Concerns1. Overly Verbose Logging (Minor)The current implementation has 6 debug log statements in a 30-line block. Consider consolidating some of these logs. The success cases may not need separate logs. 2. Breaking Change in to_hyper_close() (Medium Severity)Location: proxy_service.rs:2567-2573 The function signature suggests frame: Option where None means no close frame. However, the new implementation always returns a close frame with CloseCode::Normal and reason "ws.closed". Concerns:
Recommendation:
3. Unrelated Script Changes (Low Severity)Location: scripts/run/engine-rocksdb.sh:10-14 The addition of Pegboard timeout configurations appears unrelated to the WebSocket close fix. These extremely low timeout values (100ms) suggest this is for testing - ensure they do not accidentally get used in production. Recommendation:
Missing Elements1. Test CoverageThere are existing WebSocket tests in tests/websocket.rs, but no tests added for this specific scenario. Recommendation: Add a test case that:
2. DocumentationThe PR description is empty. Consider adding:
Performance ConsiderationsNo significant performance concerns. The added error handling has negligible overhead. Security ConsiderationsNo security concerns identified. The changes do not introduce new attack vectors or expose sensitive information. Recommendations Summary
Overall, this is a solid fix for a real issue. The error handling approach is correct, and the logging will help debug future issues. The main concern is ensuring the to_hyper_close() behavior change does not have unintended side effects. |
Code Review: WebSocket Close Frame Handling FixSummaryThis PR addresses WebSocket close frame handling issues (1006 errors) when clients close connections. The changes improve error resilience by gracefully handling failures when sending close frames to already-closing connections. ✅ What's Working Well
🔍 Observations & Minor Concerns1. Script File ChangesThe changes to +RIVET__PEGBOARD__RETRY_RESET_DURATION="100" \
+RIVET__PEGBOARD__BASE_RETRY_TIMEOUT="100" \
+RIVET__PEGBOARD__RESCHEDULE_BACKOFF_MAX_EXPONENT="1" \
+RIVET__PEGBOARD__RUNNER_ELIGIBLE_THRESHOLD="5000" \
+RIVET__PEGBOARD__RUNNER_LOST_THRESHOLD="7000" \Question: Are these Pegboard-related configuration changes intended for this PR, or should they be in a separate commit? These look like they might be development/testing settings rather than production configuration. Recommendation: If these are just for local development/testing, consider:
2. Error ContextWhile the error handling is correct, the error objects being swallowed could potentially contain useful diagnostic information. Consider if any metrics or telemetry should be recorded for these cases to track:
That said, since these are debug logs, this may be sufficient for diagnosing issues in practice. 3. Close Frame ReasonThe default close reason
Current approach is perfectly acceptable though. 🧪 Testing ConsiderationsQuestion: Have you tested these scenarios?
The existing test file 🎯 Security & Performance
📝 Code Style Compliance
Final VerdictThis is a solid bug fix that addresses a real issue with WebSocket connection handling. The core changes to Approved with minor questions about the script file changes. Consider addressing the script configuration question before merging, but the WebSocket handling changes themselves look good to merge. Suggested next steps:
|
Code ReviewSummaryThis PR addresses WebSocket close code 1006 errors (abnormal closure) when clients close connections. The fix converts fatal errors during the close handshake into warnings, allowing graceful degradation when the client has already closed. Positive Aspects
Issues and Concerns1. Unrelated Script Changes (Blocker) 2. Excessive Debug Logging (Minor) 3. Missing Test Coverage (Important) 4. Race Condition Question 5. Close Frame Reason (Nitpick) RecommendationsMust Fix:
Should Fix:
ConclusionThe core fix is sound and addresses the immediate issue. With these changes, this will be a solid improvement to WebSocket reliability. |
4078059 to
04f4430
Compare
51912f8 to
4831d26
Compare
PR Review: Fix 1006 WebSocket Close IssueSummaryThis PR addresses WebSocket close code 1006 (abnormal closure) errors by gracefully handling cases where the client has already closed the connection before the server attempts to send its close frame. Code Quality & Best Practices ✅Strengths:
Minor suggestions:
Potential Bugs or Issues
|
04f4430 to
d93280c
Compare
4831d26 to
ff5ae6a
Compare
Code ReviewOverviewThis PR addresses WebSocket close handling by making the close frame sending and flushing operations more resilient to failures when the client has already closed the connection. This is a good defensive programming practice for WebSocket error code 1006 (abnormal closure). Strengths
Issues and Suggestions1. Script file changes appear unrelatedThe changes to scripts/run/engine-rocksdb.sh add Pegboard configuration values but are not mentioned in the PR title/description. These seem unrelated to the WebSocket fix. Recommendation: Consider splitting these into a separate commit/PR, or add a description explaining why these changes are needed for testing the WebSocket fix. 2. Inconsistent error handling pattern in the fileLooking at lines 1918-1925, there is an error path that still uses .await? for the same operations, and similarly at lines 1962-1969. If the client closing the connection early is a normal scenario, these other code paths should probably use the same defensive error handling. Recommendation: Apply the same error handling pattern to all WebSocket close operations in this file for consistency. 3. Changed behavior in to_hyper_close functionThe None case now returns a close frame with code Normal and reason "ws.closed" instead of Message::Close(None). While this is probably fine, it changes the wire protocol. Questions: Is there a specific reason for this change? Have you verified this does not affect any clients expecting Close(None)? 4. Potentially excessive loggingThe new code adds 4 debug log lines for each close operation. In a high-traffic environment, this might be noisy. Recommendation: Consider consolidating to 1-2 log lines, or only log failures. 5. Missing testsThere do not appear to be any tests in the guard-core package for WebSocket handling. This specific edge case (client closes first) would be valuable to test. Recommendation: Consider adding integration tests for WebSocket close scenarios. Performance and Security
Code Quality Score: 7/10The core fix is solid, but the PR would benefit from:
Final RecommendationApprove with minor changes requested. The fix addresses a real issue, but please consider the consistency and scope concerns mentioned above. |
Merge activity
|

No description provided.