-
Notifications
You must be signed in to change notification settings - Fork 129
fix(rivetkit): fix conns not being cleaned up if actor.createConn errors
#3335
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
Code Review: Fix WebSocket Connection CleanupSummaryThis PR fixes a race condition where connections were not being cleaned up properly when Positive Changes ✅
Potential Issues & Recommendations
|
084c5e3 to
b5e9f49
Compare
c60979e to
cde5aa5
Compare
Code ReviewSummaryThis PR fixes a resource leak where WebSocket connections weren't being properly cleaned up when Positive Changes ✅
Potential Issues & Suggestions 🔍1. Race Condition Edge Case (Minor)There's a theoretical race condition between lines 205 and 208: // Store connection so we can clean on close
createdConn = conn;
// Unblock other handlers
handlersResolve({ conn, actor, connId: conn.id });If // Store connection so we can clean on close
createdConn = conn;
// Unblock other handlers
handlersResolve({ conn, actor, connId: conn.id });Actually, looking at this more carefully, the assignment is already before the resolve, so this is fine. The 2. Inconsistent Cleanup LogicIn the But: The previous code would have called 3. Consider Adding a CommentThe fix is subtle and non-obvious. Consider adding a comment explaining why // Track connection outside of scope for cleanup
// This ensures we can clean up the connection in onClose even if
// actor.createConn fails and the promise is rejected
let createdConn: AnyConn | undefined;Code Quality Notes 📝
Test Coverage 🧪Issue: I couldn't find any tests that cover the
This would prevent regressions and document the expected behavior. Security & Performance ✓
VerdictApproved with suggestions ✅ This is a solid fix for a real resource leak issue. The code change is minimal and correct. My suggestions are mostly about edge cases and testing, not blocking issues. Recommendation:
|
Code ReviewSummaryThis PR fixes a resource leak where WebSocket connections were not being properly cleaned up when Positive Changes✅ Critical Bug Fix: The PR correctly addresses a real resource leak. Previously, if ✅ Cleaner Error Handling: The new approach using ✅ Minimal Changes: The fix is surgical and doesn't introduce unnecessary complexity. Issues & Concerns1. Potential Race Condition
|
cde5aa5 to
ac85131
Compare
Code ReviewSummaryThis PR fixes a resource leak where connections weren't being cleaned up if Positive Feedback✅ Core Fix is Correct: The approach of tracking ✅ Simplified Error Handling: Removing the ✅ Handles Edge Cases: The Issues & Concerns1. Potential Race Condition (Minor)The assignment
However, for complete safety, consider whether Severity: Low (edge case, unlikely in practice) 2. Inconsistency with SSE Handler (Observation)The SSE handler (
While the WebSocket pattern is now cleaner, the inconsistency between handlers might make the codebase harder to maintain. Consider whether both should use the same pattern. Recommendation: Document why different patterns are used, or unify them in a future refactor. 3. Test Coverage (Important)There don't appear to be unit tests for Recommendation: Add tests to verify:
4. Documentation (Minor)The inline comment at line 167 ( Questions
Performance Considerations✅ No performance concerns - the changes are minimal and don't add any meaningful overhead. Security Considerations✅ No security concerns - this is a bug fix that improves resource cleanup, which could prevent DoS via resource exhaustion. Code StyleThe changes follow the existing code style and conventions in the file. No issues here. Overall AssessmentApproval: ✅ Approved with minor recommendations This is a solid bug fix that addresses a real resource leak. The implementation is clean and follows good error handling patterns. My main recommendation is to add test coverage for this error path to prevent regressions. The fix improves the robustness of the WebSocket connection lifecycle and should prevent resource leaks when actor creation fails. |
Merge activity
|
3cedf91 to
c98b4a2
Compare
ac85131 to
4de4ae9
Compare
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/limits#rate-limits |
PR Review: Connection Cleanup FixSummaryThis PR fixes a resource leak where WebSocket connections weren't being properly cleaned up when ✅ Positive Changes1. Fixes Critical Resource Leak 2. Simplifies Control Flow
This is a textbook example of when to use 3. Reduces Complexity
🔍 Code Quality ObservationsGood:
Consider:
🐛 Potential Issues & Edge Cases1. Race Condition (Minor) However, this is actually the correct behavior because:
So this edge case is already properly handled. ✅ 2. Consistency with Other Handlers 3. Error Handling in onOpen
This flow is correct. ✅ 🔐 Security ConsiderationsNo security concerns identified. The change:
⚡ Performance ConsiderationsPositive Impact:
Neutral:
🧪 Test CoverageConcern: This PR doesn't include tests for the specific bug being fixed. Recommended test cases:
The test would look something like: // Pseudo-code
test('connection cleanup when createConn errors', async () => {
const actor = await createTestActor();
const originalConnCount = actor.conns.size;
// Mock createConn to throw
actor.createConn = jest.fn().mockRejectedValue(new Error('Creation failed'));
const ws = await connectWebSocket(actor);
// Wait for error handling
await waitForWebSocketClose(ws);
// Verify no leaked connections
expect(actor.conns.size).toBe(originalConnCount);
expect(actor.__connDisconnected).toHaveBeenCalledTimes(0); // Because conn was never created
});📋 Recommendations
Final AssessmentOverall: Excellent fix ✅ This PR correctly addresses a real resource leak bug with a clean, simple solution. The use of The only significant gap is test coverage for this specific error path. I'd recommend adding tests before merging to prevent regressions. Approve with suggestion to add tests. Review generated by Claude Code - rivetkit-typescript/packages/rivetkit/src/actor/router-endpoints.ts:163-314 |

No description provided.