-
Notifications
You must be signed in to change notification settings - Fork 132
fix(rivetkit): skip sending RivetKit messages to conns that do not support it #3440
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(rivetkit): skip sending RivetKit messages to conns that do not support it #3440
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
Code Review for PR #3440SummaryThis PR introduces a protocol capability check for connection drivers to prevent RivetKit protocol messages from being sent to connections that don't support it. This is a good architectural improvement that makes the connection driver interface more explicit about protocol support. Positive Changes✅ Clear Protocol Separation: Moving ✅ Prevents Protocol Mismatches: Properly guards against sending RivetKit messages (Init, Event, etc.) to raw HTTP/WebSocket connections that don't understand them. ✅ Consistent Pattern: The check
✅ Good Logging: Appropriate warning logs when attempting to send to incompatible connections. Issues & Concerns1. Bug in
|
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: |
e8b192b to
afc9c8e
Compare
ca5b3f0 to
51a32d6
Compare
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/limits#rate-limits |
PR Review: Skip sending RivetKit messages to conns that do not support itOverviewThis PR introduces a protocol capability check for RivetKit connections, ensuring that RivetKit-specific messages (Init, subscription events, etc.) are only sent to connections that support the RivetKit protocol. This is a well-architected solution that uses capability-based design. ✅ Strengths
🐛 Potential Issues1. Missing Return Statement (rivetkit-typescript/packages/rivetkit/src/actor/conn/mod.ts:208)send(eventName: string, ...args: unknown[]) {
this.#assertConnected();
if (!this[CONN_SPEAKS_RIVETKIT_SYMBOL]) {
this.#actor.rLog.warn({
msg: "cannot send messages to this connection type",
connId: this.id,
connType: this[CONN_DRIVER_SYMBOL]?.type,
});
}
// Execution continues even if connection doesn't support RivetKit!Issue: The check logs a warning but doesn't return early. This means the code continues to execute Fix: Add an early return: if (!this[CONN_SPEAKS_RIVETKIT_SYMBOL]()) {
this.#actor.rLog.warn({
msg: "cannot send messages to this connection type",
connId: this.id,
connType: this[CONN_DRIVER_SYMBOL]?.type,
});
return;
}2. Method Invocation Inconsistency (rivetkit-typescript/packages/rivetkit/src/actor/conn/mod.ts:208)if (!this[CONN_SPEAKS_RIVETKIT_SYMBOL]) { // Missing () - checking if method existsIssue: This checks if the method exists, not if it returns true. Should be 3. Silent Event Skipping (rivetkit-typescript/packages/rivetkit/src/actor/instance/event-manager.ts:219)for (const connection of subscribers) {
if (connection[CONN_SPEAKS_RIVETKIT_SYMBOL]) { // Missing ()
// send message
}
// Silently skips non-supporting connections
}Issues:
Suggestion: Add debug logging when skipping: if (connection[CONN_SPEAKS_RIVETKIT_SYMBOL]()) {
// send message
} else {
this.#actor.rLog.debug({
msg: "skipping event for non-RivetKit connection",
eventName: name,
connId: connection.id,
connType: connection[CONN_DRIVER_SYMBOL]?.type,
});
}🔍 Minor Observations
🚀 Performance Considerations
🔒 Security ConcernsNo security issues identified. The capability-based approach actually improves security by making protocol support explicit and preventing accidental message leakage to unsupported connections. 🧪 Test Coverage RecommendationsThis PR would benefit from tests covering:
📝 Recommended ChangesCritical:
Nice to have: SummaryThis is a solid architectural improvement with clear separation of concerns. The main issues are minor (missing method invocation parentheses and return statement) but critical to fix as they would cause the feature not to work as intended. Once these are addressed, this PR will be in excellent shape. Recommendation: Request changes for the critical fixes, then approve. |
51a32d6 to
ab1c83d
Compare
Code Review: Skip sending RivetKit messages to connections that do not support itOverviewThis PR introduces a cleaner separation between connections that speak the RivetKit protocol and those that don't (raw HTTP/WebSocket connections). The approach is solid and follows good design patterns. ✅ Strengths1. Clear API Design rivetKitProtocol?: {
sendMessage(actor, conn, message): void;
}2. Consistent Pattern
3. Guard Clauses
🐛 Potential Issues1. Logic Error in if (!this[CONN_SPEAKS_RIVETKIT_SYMBOL]) {
this.#actor.rLog.warn({ /* ... */ });
}
// Code continues to send message anyway! 🚨Issue: The warning is logged but execution continues, attempting to send the message even when the connection doesn't support RivetKit protocol. This will trigger the debug log at line 187. Fix: Add an early return: if (!this[CONN_SPEAKS_RIVETKIT_SYMBOL]()) { // Note: missing () in current code
this.#actor.rLog.warn({
msg: "cannot send messages to this connection type",
connId: this.id,
connType: this[CONN_DRIVER_SYMBOL]?.type,
});
return; // ← Add this
}2. Missing Function Call Parentheses (mod.ts:208) if (!this[CONN_SPEAKS_RIVETKIT_SYMBOL]) { // ❌ Symbol, not function resultShould be: if (!this[CONN_SPEAKS_RIVETKIT_SYMBOL]()) { // ✅ Function callThe 💡 Suggestions1. Type Safety Enhancement Consider making get [CONN_SPEAKS_RIVETKIT_SYMBOL](): boolean {
return this[CONN_DRIVER_SYMBOL]?.rivetKitProtocol !== undefined;
}Then usage becomes: if (conn[CONN_SPEAKS_RIVETKIT_SYMBOL]) { /* ... */ }This matches the pattern used for other symbol-based accessors in the class. 2. Documentation Consider adding a JSDoc comment to /**
* If defined, this connection driver talks the RivetKit client protocol (see
* schemas/client-protocol/).
*
* Should be implemented by: websocket driver
* Should NOT be implemented by: raw-websocket, http, raw-request drivers
*/3. Test Coverage No tests were modified/added in this PR. Consider adding tests for:
🔒 Security ConsiderationsNo security concerns identified. The changes properly prevent protocol messages from being sent to unsupported connection types, which could otherwise cause errors or unexpected behavior. ⚡ Performance ConsiderationsThe changes add minimal overhead (simple boolean checks) and actually improve performance by avoiding unnecessary serialization and send attempts for connections that don't support the protocol. SummaryCritical Issues: 2
Recommendations:
Once the critical issues are addressed, this is a solid improvement to the codebase! 👍 |

No description provided.