@@ -337,6 +337,7 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
337
337
338
338
// Force context abort now.
339
339
void abort (kj::Exception&& e) {
340
+ abortException = kj::cp (e);
340
341
abortFulfiller->reject (kj::mv (e));
341
342
}
342
343
@@ -853,6 +854,7 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
853
854
854
855
DeleteQueuePtr deleteQueue;
855
856
857
+ kj::Maybe<kj::Exception> abortException;
856
858
kj::Own<kj::PromiseFulfiller<void >> abortFulfiller;
857
859
kj::ForkedPromise<void > abortPromise = nullptr ;
858
860
@@ -1014,6 +1016,12 @@ kj::PromiseForResult<Func, Worker::Lock&> IoContext::run(
1014
1016
template <typename Func>
1015
1017
kj::PromiseForResult<Func, Worker::Lock&> IoContext::run (
1016
1018
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
+
1017
1025
kj::Promise<Worker::AsyncLock> asyncLockPromise = nullptr ;
1018
1026
KJ_IF_SOME (a, actor) {
1019
1027
if (inputLock == kj::none) {
0 commit comments