Skip to content

Commit ae09be0

Browse files
committed
fix(rivetkit): make duplicate sleep requests idempotent
1 parent b81dab2 commit ae09be0

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

rivetkit-rust/packages/rivetkit-core/src/actor/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ impl ActorContext {
412412
};
413413
}
414414
if self.0.sleep_requested.swap(true, Ordering::SeqCst) {
415-
return Err(ActorLifecycleError::Stopping.build())
416-
.context("sleep already requested for this generation");
415+
return Ok(());
417416
}
418417
self.cancel_sleep_timer();
419418
if Handle::try_current().is_ok() {

rivetkit-typescript/packages/rivetkit/tests/driver/actor-sleep-db.test.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,7 @@ describeDriverMatrix("Actor Sleep Db", (driverTestConfig) => {
776776
expect(events).toContain("waituntil-after-reject");
777777
});
778778

779-
// TODO(#4705): Root-cause duplicate sleep-call semantics and re-enable this coverage.
780-
test.skip("double sleep call is a no-op", async (c) => {
779+
test("double sleep call is a no-op", async (c) => {
781780
const { client } = await setupDriverTest(c, driverTestConfig);
782781

783782
// Use a connection to send the sleep trigger, because
@@ -790,15 +789,10 @@ describeDriverMatrix("Actor Sleep Db", (driverTestConfig) => {
790789

791790
await waitForConnectionReady(connection);
792791

793-
// Trigger sleep twice rapidly via the connection.
794-
// The second call should be a no-op because
795-
// #sleepCalled is already true.
796-
await connection.triggerSleep();
797-
try {
798-
await connection.triggerSleep();
799-
} catch {
800-
// May throw if actor already stopping
801-
}
792+
// Trigger sleep twice from the same action invocation. The second
793+
// call should be a no-op because the first call already requested
794+
// sleep for this actor generation.
795+
await connection.triggerSleepTwice();
802796

803797
// Wait for sleep to complete
804798
await waitFor(driverTestConfig, 1500);

0 commit comments

Comments
 (0)