Skip to content

Commit e78f432

Browse files
committed
Rethrow abort exception on IoContext::run
We're seeing errors getting reported from actors trying to run promises without an active request. We've determined this is from tasks trying to run after an actor's IO context has been aborted. This change stores the abort exception in the `IoContext` and rethrows it in `IoContext::run`.
1 parent f82812e commit e78f432

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/workerd/io/io-context.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
336336

337337
// Force context abort now.
338338
void abort(kj::Exception&& e) {
339+
abortException = kj::cp(e);
339340
abortFulfiller->reject(kj::mv(e));
340341
}
341342

@@ -852,6 +853,7 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
852853

853854
DeleteQueuePtr deleteQueue;
854855

856+
kj::Maybe<kj::Exception> abortException;
855857
kj::Own<kj::PromiseFulfiller<void>> abortFulfiller;
856858
kj::ForkedPromise<void> abortPromise = nullptr;
857859

@@ -1013,6 +1015,12 @@ kj::PromiseForResult<Func, Worker::Lock&> IoContext::run(
10131015
template <typename Func>
10141016
kj::PromiseForResult<Func, Worker::Lock&> IoContext::run(
10151017
Func&& func, kj::Maybe<InputGate::Lock> inputLock) {
1018+
// Before we try running anything, let's make sure our IoContext hasn't been aborted. If it has
1019+
// been aborted, there's likely not an active request so later operations will fail anyway.
1020+
KJ_IF_SOME(ex, abortException) {
1021+
kj::throwFatalException(kj::cp(ex));
1022+
}
1023+
10161024
kj::Promise<Worker::AsyncLock> asyncLockPromise = nullptr;
10171025
KJ_IF_SOME(a, actor) {
10181026
if (inputLock == kj::none) {

0 commit comments

Comments
 (0)