fix(rivetkit): fire abort signal on shutdown finalize#4957
Conversation
11daf92 to
f677b5c
Compare
3c7167b to
19adfab
Compare
PR #4957 Review: fire abort signal on shutdown finalizeOverviewThis PR changes the semantics of c.abortSignal / c.aborted: the abort signal now fires at the end of shutdown finalization, not at the start of the grace period (and not early on ctx.destroy()). The motivation is sound - the old behavior meant c.aborted was true inside onSleep/onDestroy hooks, which was confusing and unexpected for users. Code QualityRust (context.rs / task.rs) - solid changes:
TypeScript (mod.ts) - clean:
Tests - correct:
Main Concern: Tick Loop Pattern Is Broken by New SemanticsThe documentation now says (lifecycle.mdx line 291):
But the tick loop example on line 303 still uses the old pattern - a // run handler calls c.abortSignal.addEventListener("abort", resolve, { once: true })
// inside a while (!c.aborted) loop to exit on shutdownWith the new semantics this loop will never exit cleanly during shutdown:
This turns every tick-loop actor into a run-handler leak on every sleep/destroy cycle. The same issue applies to the second example at lifecycle.mdx line 1062. Suggested fix: Update both tick-loop examples to reflect the new intended pattern. If the signal is now only for post-finalization cleanup (e.g. releasing external resources), show that use case instead. For breaking out of a run loop during shutdown, the docs should either recommend c.keepAwake() to let the actor settle naturally before sleep, or show a separate AbortController (as queues.mdx line 428 now correctly advises). Minor Issues
SummaryThe core behavioral change is correct and well-implemented. The exception-safety refactor in finalize_shutdown and the finally-placement in TypeScript are both good. The main gap is that the tick-loop code examples in lifecycle.mdx are now semantically broken - they still rely on c.abortSignal to exit the run loop, but the signal no longer fires until after the run handler is abandoned. Those examples need updating before this merges. |
f677b5c to
878a458
Compare
|
PR Review - fix(rivetkit) - fire abort signal on shutdown finalize Overview This PR unifies the abort signal firing path for both sleep and destroy shutdown modes. Previously, calling ctx.destroy() would synchronously fire the abort signal the moment user code called it. Now, the abort signal fires when grace starts, consistently for both sleep and destroy. The change aligns behavior with documented semantics and prevents surprising mid-action aborts. What Changed
Code Quality Strengths:
Issues and Suggestions Minor - Warning message is less actionable after the change Both joinRunHandleOrWarn log sites were updated from a message that told users what API to use (c.abortSignal) to a vaguer one. Consider: Minor - Queue test semantic drift In queue.rs, the test changed from queue.mark_destroy_requested() to queue.cancel_actor_abort_signal(). Those two calls are no longer equivalent: the old call also set the destroy-requested flag. If the test was exercising that the queue correctly unblocks on a destroy request, it should also set the destroy flag, or the comment should explain why the signal-only cancel is sufficient. Nit - abortActorSignal early return is redundant AbortController.abort() is idempotent - calling it on an already-aborted controller is a no-op. The signal.aborted guard before calling abort() is harmless but unnecessary since the outer try/catch already handles edge cases. Test Coverage
Summary Solid fix with clean implementation. The core change is correct and eliminates a surprising early-abort footgun. The two items worth addressing before merge are the less-actionable warning message and the queue test semantic drift. Everything else is minor. |
878a458 to
c2198e9
Compare
19adfab to
314c8ff
Compare
c2198e9 to
7764046
Compare

Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: