Skip to content

Commit ff5804e

Browse files
authored
propagate abort errors correctly (#4437)
1 parent 669216e commit ff5804e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/workerd/io/worker-entrypoint.c++

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,21 @@ kj::Promise<bool> WorkerEntrypoint::test() {
729729
[](IoContext& context, kj::Own<IoContext::IncomingRequest> request) -> kj::Promise<bool> {
730730
TRACE_EVENT("workerd", "WorkerEntrypoint::test() waitForFinished()");
731731
auto result = co_await request->finishScheduled();
732+
733+
if (result == IoContext_IncomingRequest::FinishScheduledResult::ABORTED) {
734+
// If the test handler throws an exception (without aborting - just a regular exception),
735+
// then `outcome` ends up being EventOutcome::EXCEPTION, which causes us to return false.
736+
// But in that case we are separately relying on the exception being logged as an uncaught
737+
// exception, rather than throwing it.
738+
// This is why we don't rethrow the exception but rather log it as an uncaught exception.
739+
try {
740+
co_await context.onAbort();
741+
} catch (...) {
742+
auto exception = kj::getCaughtExceptionAsKj();
743+
KJ_LOG(ERROR, exception);
744+
}
745+
}
746+
732747
bool completed = result == IoContext_IncomingRequest::FinishScheduledResult::COMPLETED;
733748
auto outcome = completed ? context.waitUntilStatus() : EventOutcome::EXCEEDED_CPU;
734749
co_return outcome == EventOutcome::OK;

0 commit comments

Comments
 (0)