-
Notifications
You must be signed in to change notification settings - Fork 129
fix(rivetkit): fix actors trying to sleep after stop started #3384
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
|
0898db1 to
8d4492f
Compare
fb0fa44 to
30a829e
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 a race condition where actors could attempt to sleep after a stop operation has already started. The fix adds proper guards to prevent sleep operations when Positive Observations✅ Correct Guard Placement: The checks for
✅ Defensive Programming: Multiple layers of protection ensure the race condition is caught at different levels ✅ Improved Logging: Log messages are now more descriptive (e.g., "cannot call _startSleep twice, actor already sleeping" vs "already sleeping actor") Issues & Concerns1. Debug Code Left in Production
|
Code ReviewI've reviewed PR #3384 which fixes actors trying to sleep after stop has started. Overall, this is a solid bug fix that addresses a race condition in the actor lifecycle. Here's my detailed feedback: ✅ Strengths
|
Code ReviewSummaryThis PR fixes a race condition where actors attempt to sleep after stop has been initiated. The changes add appropriate guards to prevent sleep operations during shutdown. Positive Aspects
Issues & Concerns1. Debug Code Left in Production (Critical)// engine/sdks/typescript/runner/src/mod.ts:870
console.trace("send actor intent", actorId, intentType);Issue: This Recommendation: Remove this line or convert it to a proper debug log: this.log?.debug({
msg: "send actor intent",
actorId,
intentType,
});2. Removed Sleep Timeout Cleanup (Potential Issue)The PR removes this line from if (this.#sleepTimeout) clearTimeout(this.#sleepTimeout);Analysis:
Question: Is this intentional? The 3. Potential Race Condition// #resetSleepTimer at line 1924
if (this.#stopCalled) return; // Early return before clearing timeout
// Later at line 1935
if (this.#sleepTimeout) {
clearTimeout(this.#sleepTimeout);
this.#sleepTimeout = undefined;
}Issue: If Recommendation: Consider clearing the timeout before the early return: #resetSleepTimer() {
if (this.#config.options.noSleep || \!this.#sleepingSupported) return;
// Clear any existing timeout first
if (this.#sleepTimeout) {
clearTimeout(this.#sleepTimeout);
this.#sleepTimeout = undefined;
}
// Don't sleep if already stopping
if (this.#stopCalled) return;
// ... rest of the function
}4. Missing Test CoverageIssue: There don't appear to be tests covering the sleep-during-stop race condition this PR addresses. Recommendation: Add a test case that:
Minor Observations
Questions for Author
RecommendationsMust Fix:
Should Consider:
Overall AssessmentThe core fix is sound and addresses a real race condition. The main concern is the debug code that should be removed, and it would benefit from test coverage to prevent regressions. |
8d4492f to
f9b3de2
Compare
30a829e to
f612c0f
Compare
PR Review: Fix actors trying to sleep after stop startedSummaryThis PR addresses a race condition where actors would attempt to sleep after the stop sequence has already begun. The fix adds proper guards to prevent sleep operations when Code Quality & Best Practices✅ Positive Observations:
Potential Bugs & IssuesCritical: None identified. The logic appears sound. Medium Priority:
Performance ConsiderationsNo significant performance impact. The added conditional checks are minimal and occur in code paths that are not performance-critical (shutdown sequences). Security ConcernsNo security issues identified. The changes properly prevent operations during invalid states, which actually improves robustness. Test Coverage✅ Excellent test coverage exists: The existing test suite in
📋 Recommendation: Consider adding a specific test case for the race condition this PR fixes: test("actor does not sleep when stop is called during sleep timer", async (c) => {
const { client } = await setupDriverTest(c, driverTestConfig);
const sleepActor = client.sleep.getOrCreate();
// Wait almost until sleep timeout
await waitFor(driverTestConfig, SLEEP_TIMEOUT - 100);
// Manually trigger stop (this would need to be exposed for testing)
// Verify that sleep does not occur
// Verify actor stopped cleanly without attempting to sleep
});This would require exposing some testing hooks to manually trigger the stop sequence, which may not be worth it given the complexity. The existing tests likely cover this implicitly. Minor Issues
RecommendationsBefore merging:
Optional improvements:
Overall AssessmentStatus: Approve with minor changes This is a solid fix for a legitimate race condition bug. The implementation is clean and follows the codebase patterns. The main blocker is removing the debugging Severity of bug fixed: Medium - Could cause unexpected behavior and error logs during shutdown sequences Great work on identifying and fixing this race condition! 🎯 |
Code ReviewSummaryThis PR fixes a race condition where actors could attempt to sleep after the stop process has already started, which could lead to inconsistent state or errors during shutdown. Positive Changes ✅1. Race condition prevention in
2. Early exit in
3. Runner shutdown check (engine/sdks/typescript/runner/src/mod.ts:175-180)
Concerns & Questions
|
f612c0f to
f5907de
Compare
Code ReviewSummaryThis PR addresses a race condition where actors attempt to sleep after the stop process has already begun. The fix adds proper guards to prevent sleep operations during shutdown. Positive Aspects ✅
Issues & Concerns 🔴Critical: Sleep Timeout Not Cleared in
|
Merge activity
|

No description provided.