-
Notifications
You must be signed in to change notification settings - Fork 44
feat(core): add abort controller & implement waitUntil #1200
feat(core): add abort controller & implement waitUntil #1200
Conversation
|
Claude finished @NathanFlurry's task —— View job Code Review: feat(core): add abort controller & implement waitUntilSummary: ✅ Positive Aspects1. Clear Naming & Documentation
2. Robust Shutdown Handling
3. Consistent Error Handling
|
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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. |
packages/core/src/actor/instance.ts
Outdated
| if (this.#sleepCalled) | ||
| throw new errors.InternalError("Actor is going to sleep"); | ||
| if (this.#stopCalled) throw new errors.InternalError("Actor is stopping"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that the properties #sleepCalled and #stopCalled are being checked in the #assertReady() method, but they don't seem to be defined as class properties in the visible code. These properties need to be declared at the class level (similar to how #backgroundPromises and other private fields are declared) and properly initialized to avoid potential runtime errors.
Consider adding these property declarations to the class, for example:
#sleepCalled = false;
#stopCalled = false;Then ensure they're properly set to true in the respective _sleep() and _stop() methods to maintain accurate lifecycle state tracking.
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
| async #waitBackgroundPromises(timeoutMs: number) { | ||
| const pending = this.#backgroundPromises; | ||
| if (pending.length === 0) { | ||
| logger().debug("no background promises"); | ||
| return; | ||
| } | ||
|
|
||
| // Race promises with timeout to determine if pending promises settled fast enough | ||
| const timedOut = await Promise.race([ | ||
| Promise.allSettled(pending).then(() => false), | ||
| new Promise<true>((resolve) => | ||
| setTimeout(() => resolve(true), timeoutMs), | ||
| ), | ||
| ]); | ||
|
|
||
| // TODO: | ||
| //Deno.exit(0); | ||
| if (timedOut) { | ||
| logger().error( | ||
| "timed out waiting for background tasks, background promises may have leaked", | ||
| { | ||
| count: pending.length, | ||
| timeoutMs, | ||
| }, | ||
| ); | ||
| } else { | ||
| logger().debug("background promises finished"); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential issues with #waitBackgroundPromises implementation:
-
Race condition with promise collection: The method captures
this.#backgroundPromisesat the beginning, but new promises could be added via_waitUntil()during execution. This means some promises might not be properly awaited during shutdown. -
Timer resource leak: The
setTimeoutin the race condition creates a timer that isn't explicitly cleared if promises resolve first. Consider storing the timeout ID and clearing it when no longer needed:
const timeoutId = setTimeout(() => resolve(true), timeoutMs);
Promise.allSettled(pending).then(() => {
clearTimeout(timeoutId);
resolve(false);
});- Promise array management: There doesn't appear to be a mechanism to remove completed promises from
#backgroundPromises. Without cleanup, this array will grow indefinitely during the actor's lifetime, potentially causing memory issues.
Consider implementing a promise tracking system that removes completed promises and properly handles the race condition during shutdown.
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
| try { | ||
| this.#abortController.abort(); | ||
| } catch {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The abort() method is wrapped in an empty try-catch block that suppresses all errors without logging. While AbortController.abort() rarely throws, silent error handling can hide unexpected issues during the critical shutdown sequence. Consider either:
- Removing the try-catch if
abort()is not expected to throw in your implementation - Adding error logging inside the catch block
- Catching only specific expected exceptions
This would improve debuggability if unexpected behavior occurs during shutdown.
| try { | |
| this.#abortController.abort(); | |
| } catch {} | |
| try { | |
| this.#abortController.abort(); | |
| } catch (error) { | |
| console.error("Error aborting actor controller:", error); | |
| } |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
c3c1dc0 to
7d936c9
Compare
|
Claude finished @NathanFlurry's task —— View job PR Review: feat(core): add abort controller & implement waitUntilI'll review this PR focusing on:
SummaryThis PR implements abort controller functionality and renames ✅ Strengths1. Improved API Design
2. Enhanced Shutdown Logic
3. Configuration Management
|
Merge activity
|

No description provided.