Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Await actor alarm deletion cache flush outputGate when alarm succeeds #1601

Merged
merged 1 commit into from
Feb 5, 2024
Merged
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
14 changes: 14 additions & 0 deletions src/workerd/io/worker-entrypoint.c++
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,20 @@ kj::Promise<WorkerInterface::AlarmResult> WorkerEntrypoint::runAlarmImpl(
return lock.getGlobalScope().runAlarm(scheduledTime, lock, handler);
});

// The alarm handler was successfully complete. We must guarantee this same alarm does not
// run again.
if (result.outcome == EventOutcome::OK){
// When an alarm handler completes its execution, the alarm is marked ready for deletion in
// actor-cache. This alarm change will only be reflected in the alarmsXX table, once cache
// flushes and changes are written to CRDB.
// If there are any pending flushes, they are locked with the actor output gate until
// they complete. We should wait until the output gate locks are released.
// If we don't wait, it's possible for alarm manager to pull the wrong alarm value (the
// same alarm that just completed) from CRDB before these changes are actually made,
// rerunning it, when it shouldn't.
co_await actor.getOutputGate().wait();
}

// We succeeded, inform any other entrypoints that may be waiting upon us.
af.fulfill(result);
cancellationGuard.cancel();
Expand Down
Loading