-
Notifications
You must be signed in to change notification settings - Fork 129
fix(rivetkit): correctly handle hibernatable websocket reconnection with persisted request ids #3398
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
|
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
…ith persisted request ids
b4fdc49 to
e43ae38
Compare
PR Review: Hibernatable WebSocket Reconnection FixSummaryThis PR correctly addresses the hibernatable WebSocket reconnection issue by persisting the Positive Aspects ✅
Issues & Concerns 🔴1. Critical: Missing Driver State Update on ReconnectionLocation: The hibernatable reconnection path updates the socket but doesn't update the driver state: // Update with new driver state
existingConn.__socket = socket;
existingConn.__persist.lastSeen = Date.now();However, the regular reconnection path (lines 1120-1130) properly updates existingConn.__socket = socket;
existingConn.__driverState = socket.driverState; // ← Missing in hibernatable path
existingConn.__persist.lastSeen = Date.now();Impact: The connection will have the new socket but retain stale driver state, which could cause issues with WebSocket operations. Fix: Add 2. Potential Race Condition in Status CheckLocation: The TODO comment highlights a real issue: // TODO: isHibernatible might be true while the actual hibernatable websocket has disconnected
if (this.__socket || this.isHibernatable) {
return "connected";
}The Impact: Recommendation: Either:
3. Logic Duplication in Driver CleanupLocation: Both the hibernatable and regular reconnection paths have nearly identical driver cleanup logic. This violates DRY principles and makes maintenance harder. Recommendation: Extract to a helper method: private cleanupExistingDriverState(
conn: Conn<S, CP, CS, V, I, DB>,
reason: string
) {
if (conn.__driverState) {
const driverKind = getConnDriverKindFromState(conn.__driverState);
const driver = CONN_DRIVERS[driverKind];
if (driver.disconnect) {
driver.disconnect(this, conn, (conn.__driverState as any)[driverKind], reason);
}
}
}4. Inconsistent Warning vs Debug LoggingLocation: this.#rLog.warn({
msg: "found existing driver state on hibernatable websocket",
// ...
});This warning suggests an unexpected condition, but in the regular reconnection path (line 1107), the same scenario has no logging at all. Is this truly warn-worthy, or should it be debug-level? Recommendation: Either add similar warnings to the regular path or downgrade to debug level for consistency. 5. Performance: Inefficient Array SearchLocation: Multiple locations use Examples:
Issue: Converting to array and linear searching is O(n) each time. With many connections, this could become a bottleneck. Recommendation: Consider maintaining a Map of 6. Missing Test CoverageNo tests found for hibernatable WebSocket reconnection. This is critical functionality that should have:
Recommendation: Add test coverage, especially for the reconnection logic in 7. Typo in CommentLocation: /** Last time the socket was seen. This is set when disconnected so we can determine when we need to clean this up. */"disconnected" was corrected in the diff, but the comment doesn't match the actual behavior - Recommendation: Clarify that it's updated on any activity, not just disconnect. 8. Type Safety: Non-null Assertion OperatorLocation: Multiple uses of While the code checks existence before using Recommendation: Use TypeScript's type narrowing more explicitly or destructure with defaults. Minor Issues
|
Pull Request ReviewSummaryThis PR fixes a critical issue with hibernatable WebSocket reconnection handling in RivetKit. The fix ensures that persisted request IDs are correctly used to identify and reconnect hibernatable WebSocket connections, preventing duplicate connection creation on reconnection. Code Quality & Best Practices ✅Strengths:
Suggestions:
Potential Bugs & Issues 🔍
Performance Considerations ⚡
Security Concerns 🔒No major security issues found, but some considerations:
Test Coverage 📋Concerns:
Recommendations:
Additional NotesWhat This PR Fixes:
Architecture Improvement: VerdictOverall Assessment: Good Fix ✅ This PR correctly addresses the hibernatable WebSocket reconnection issue. The main concerns are:
Recommendation: Approve with suggestions for follow-up improvements, particularly around test coverage and performance optimization for high-connection scenarios. 🤖 Generated with Claude Code |

No description provided.