diff --git a/src/workerd/api/global-scope.c++ b/src/workerd/api/global-scope.c++ index 09eab28b426..6459643abc0 100644 --- a/src/workerd/api/global-scope.c++ +++ b/src/workerd/api/global-scope.c++ @@ -395,6 +395,7 @@ kj::Promise ServiceWorkerGlobalScope::runAlarm( } return WorkerInterface::AlarmResult { .retry = true, + .retryCountsAgainstLimit = !context.isOutputGateBroken(), .outcome = outcome }; }).then([&context](WorkerInterface::AlarmResult result) -> kj::Promise { @@ -411,6 +412,7 @@ kj::Promise ServiceWorkerGlobalScope::runAlarm( } return WorkerInterface::AlarmResult { .retry = true, + .retryCountsAgainstLimit = false, .outcome = EventOutcome::EXCEPTION }; }); diff --git a/src/workerd/io/io-context.c++ b/src/workerd/io/io-context.c++ index adb06b25e4c..a8a485d5f87 100644 --- a/src/workerd/io/io-context.c++ +++ b/src/workerd/io/io-context.c++ @@ -318,6 +318,14 @@ kj::Maybe>> IoContext::waitForOutputLocksIfNecessaryIoOw }); } +bool IoContext::isOutputGateBroken() { + KJ_IF_MAYBE(a, actor) { + return a->getOutputGate().isBroken(); + } else { + return false; + } +} + bool IoContext::isInspectorEnabled() { return worker->getIsolate().isInspectorEnabled(); } diff --git a/src/workerd/io/io-context.h b/src/workerd/io/io-context.h index 8027dd72358..3542225b05e 100644 --- a/src/workerd/io/io-context.h +++ b/src/workerd/io/io-context.h @@ -352,6 +352,12 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler // // Use the ...IoOwn() overload if you need to store this promise in a JS API object. + bool isOutputGateBroken(); + // Check if the output gate (only used by actors) is currently broken. This indicates that there + // was a problem with committing storage writes. + // + // For non-actor requests, this always returns false. + template kj::Promise lockOutputWhile(kj::Promise promise); // Lock output until the given promise completes. diff --git a/src/workerd/io/io-gate.c++ b/src/workerd/io/io-gate.c++ index 0bc3e69d0eb..faefb150ab1 100644 --- a/src/workerd/io/io-gate.c++ +++ b/src/workerd/io/io-gate.c++ @@ -302,6 +302,10 @@ kj::Promise OutputGate::onBroken() { } } +bool OutputGate::isBroken() { + return brokenState.is(); +} + void END_OUTPUT_LOCK_CANCELATION_STACK_START_WAITER_STACK() {} kj::Exception OutputGate::makeUnfulfilledException() { diff --git a/src/workerd/io/io-gate.h b/src/workerd/io/io-gate.h index 29e0682b769..8eaef00436f 100644 --- a/src/workerd/io/io-gate.h +++ b/src/workerd/io/io-gate.h @@ -269,6 +269,8 @@ class OutputGate { // // This method can only be called once. + bool isBroken(); + private: Hooks& hooks; diff --git a/src/workerd/io/worker-interface.c++ b/src/workerd/io/worker-interface.c++ index b72d05a930f..2279e57a93d 100644 --- a/src/workerd/io/worker-interface.c++ +++ b/src/workerd/io/worker-interface.c++ @@ -312,6 +312,7 @@ kj::Promise RpcWorkerInterface::runAlarm(kj::Date auto respResult = resp.getResult(); return WorkerInterface::AlarmResult { .retry = respResult.getRetry(), + .retryCountsAgainstLimit = respResult.getRetryCountsAgainstLimit(), .outcome = respResult.getOutcome() }; }); diff --git a/src/workerd/io/worker-interface.capnp b/src/workerd/io/worker-interface.capnp index 91b8db7e066..9c13d952e16 100644 --- a/src/workerd/io/worker-interface.capnp +++ b/src/workerd/io/worker-interface.capnp @@ -87,7 +87,8 @@ struct ScheduledRun @0xd98fc1ae5c8095d0 { struct AlarmRun @0xfa8ea4e97e23b03d { outcome @0 :EventOutcome; - retry @1 : Bool; + retry @1 :Bool; + retryCountsAgainstLimit @2 :Bool = true; } interface EventDispatcher @0xf20697475ec1752d { diff --git a/src/workerd/io/worker-interface.h b/src/workerd/io/worker-interface.h index b5c76cb1f2d..d65e81ddbe0 100644 --- a/src/workerd/io/worker-interface.h +++ b/src/workerd/io/worker-interface.h @@ -52,6 +52,7 @@ class WorkerInterface: public kj::HttpService { struct AlarmResult { bool retry = true; + bool retryCountsAgainstLimit = true; EventOutcome outcome = EventOutcome::UNKNOWN; };