Skip to content

Commit c03a25b

Browse files
Merge pull request #3699 from cloudflare/fix/abort-ex-on-run
Rethrow abort exception on IoContext::run
2 parents 7581edc + e78f432 commit c03a25b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/workerd/io/io-context.h

+8
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
337337

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

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

854855
DeleteQueuePtr deleteQueue;
855856

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

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

0 commit comments

Comments
 (0)