-
Notifications
You must be signed in to change notification settings - Fork 146
fix(engine-runner): handle shutdown close codes correctly #3896
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
base: 01-13-chore_gas_add_overview_and_history_docs
Are you sure you want to change the base?
Conversation
Code Review - PR #3896: fix(engine-runner): handle shutdown close codes correctlyOverviewThis PR refactors the shutdown handling logic in the Runner class by:
Positive Changes1. Elimination of Redundant State ✓
2. Improved Control Flow ✓
3. Consistent State Management ✓
Concerns & Suggestions1. Potential Race Condition in Shutdown Method The async shutdown(immediate: boolean, exit: boolean = false) {
if (this.#shutdown) {
return;
}
this.#shutdown = true; // Set immediately
// ... cleanup code followsIssue: If the WebSocket close event fires during the shutdown cleanup operations (which is likely, since shutdown may close the WebSocket), the close handler will see However, there's a subtle concern: The old code structure had the shutdown check as 2. Missing Special Case Handling The old code had special handling for the // OLD CODE (removed):
if (closeError?.group === "pegboard" && closeError?.error === "runner_shutdown") {
this.log?.info("runner shutdown");
}This special case has been removed entirely. Question: Is this intentional? If the server sends a
Recommendation: Clarify whether 3. onDisconnected Called Multiple Times ℹ️ The
This is consistent with the old behavior, but worth noting that consumers of this API should expect 4. Cleanup Ordering ✓ The async shutdown(immediate: boolean, exit: boolean = false) {
// ...
if (this.#ackInterval) {
clearInterval(this.#ackInterval);
this.#ackInterval = undefined;
}
// ...
}However, this creates a slight redundancy. If the WebSocket closes during normal operation (not shutdown), the interval is cleared in the close handler. If it closes during shutdown, the interval is cleared in the Testing ConsiderationsMissing Test Coverage ❌ Looking at
Recommendation:
Performance ConsiderationsNo Concerns ✓
Security ConsiderationsNo Concerns ✓
Code Style & ConventionsFollows CLAUDE.md ✓
SummaryOverall Assessment: The PR makes good improvements to the shutdown logic by eliminating redundancy and improving clarity. However, there are two key questions that should be addressed:
Recommendation:
Risk Level: Medium - The core logic appears sound, but the removal of special case handling could cause issues if it was serving an important purpose. |
More templates
@rivetkit/cloudflare-workers
@rivetkit/db
@rivetkit/framework-base
@rivetkit/next-js
@rivetkit/react
rivetkit
@rivetkit/sql-loader
@rivetkit/virtual-websocket
@rivetkit/engine-runner
@rivetkit/engine-runner-protocol
commit: |
600206d to
55a38d5
Compare
654b4e9 to
c023ef5
Compare
715b5e8 to
d6cf484
Compare
c023ef5 to
af232ee
Compare
af232ee to
1c80e13
Compare
d6cf484 to
13e2511
Compare

Fixes RVT-5333