Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export const dbActorDrizzle = actor({
},
},
options: {
actionTimeout: 120_000,
sleepTimeout: 100,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export const dbActorRaw = actor({
},
},
options: {
actionTimeout: 120_000,
sleepTimeout: 100,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ function getCounts(actorId: string): LifecycleCounts {
};
}

function getTotalCleanupCount(): number {
let total = 0;
for (const count of cleanupCounts.values()) {
total += count;
}
return total;
}

const baseProvider = db({
onMigrate: async (dbHandle) => {
await dbHandle.execute(`
Expand Down Expand Up @@ -125,5 +133,8 @@ export const dbLifecycleObserver = actor({
getCounts: (_c, actorId: string) => {
return getCounts(actorId);
},
getTotalCleanupCount: () => {
return getTotalCleanupCount();
},
},
});
15 changes: 13 additions & 2 deletions rivetkit-typescript/packages/rivetkit/src/actor/instance/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,10 @@ export class ActorInstance<
this.#sleepTimeout = undefined;
}

// Abort listeners
// Abort listeners in the canonical stop path.
// This must run for all stop modes, including sleep and remote stop.
// Destroy may have already triggered an early abort, but repeating abort
// is intentional and safe.
try {
this.#abortController.abort();
} catch { }
Expand Down Expand Up @@ -574,6 +577,14 @@ export class ActorInstance<
}
this.#destroyCalled = true;

// Abort immediately so in flight waits can exit before the driver stop
// handshake completes.
// The onStop path will call abort again as a safety net for all stop
// modes.
try {
this.#abortController.abort();
} catch {}

const destroy = this.driver.startDestroy.bind(
this.driver,
this.#actorId,
Expand Down Expand Up @@ -958,7 +969,7 @@ export class ActorInstance<
* Errors are propagated to the caller.
*/
async keepAwake<T>(promise: Promise<T>): Promise<T> {
this.assertReady();
this.assertReady(true);

this.#activeKeepAwakeCount++;
this.resetSleepTimer();
Expand Down
Loading
Loading