Skip to content

Commit 28a6369

Browse files
committed
fix(rivetkit): persist native onSleep state on errors
1 parent 5ff98a4 commit 28a6369

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

  • rivetkit-typescript/packages/rivetkit/src/registry

rivetkit-typescript/packages/rivetkit/src/registry/native.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3950,16 +3950,19 @@ export function buildNativeFactory(
39503950
const actorCtx = makeActorCtx(ctx);
39513951
try {
39523952
if (onSleep) {
3953-
await onSleep(actorCtx);
3954-
if (runtime.kind === "wasm") {
3955-
// Wasm cannot use the native context save helper here because
3956-
// the runtime owns the serialized state handoff.
3957-
await runtime.actorSaveState(
3958-
ctx,
3959-
actorCtx.serializeForTick("save"),
3960-
);
3961-
} else {
3962-
await actorCtx.saveState({ immediate: true });
3953+
try {
3954+
await onSleep(actorCtx);
3955+
} finally {
3956+
if (runtime.kind === "wasm") {
3957+
// Wasm cannot use the native context save helper here because
3958+
// the runtime owns the serialized state handoff.
3959+
await runtime.actorSaveState(
3960+
ctx,
3961+
actorCtx.serializeForTick("save"),
3962+
);
3963+
} else {
3964+
await actorCtx.saveState({ immediate: true });
3965+
}
39633966
}
39643967
}
39653968
} finally {

0 commit comments

Comments
 (0)