Repository navigation
Don't throw from the fail-open KJ_DEFER in request() - #8670
Conversation
When a fetch handler that called passThroughOnException() fails, WorkerEntrypoint::request() opens the fail-open channel inside a KJ_DEFER. That destructor runs while the handler's exception unwinds, so if opening the channel throws, the process terminates. A dynamic Worker with `globalOutbound: null` does exactly that: its null outbound throws "not permitted to access the internet" from startRequest(). Catch the failure and fail open to a WorkerInterface that rejects with it. The fail-open path then responds with a 500, the same as when the channel opens lazily and the request through it fails, as a channel to another process does.
There was a problem hiding this comment.
✅ Approved — A small, targeted fix that stops a throw from a destructor from terminating the process, with a regression test. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The KJ_TRY/KJ_CATCH around getSubrequestChannelNoChecks stops the KJ_DEFER destructor from throwing while the handler's exception unwinds. It falls back to the existing WorkerInterface::fromException helper, so the fail-open path responds with a 500. The new test in worker-loader-test.js covers a dynamic Worker with globalOutbound: null.
📝 Documentation: ✅ LGTM
The new code comment describes how the code behaves now and why the destructor must not throw.
Reviewed commit: 110a3351
When a fetch handler that called passThroughOnException() fails, WorkerEntrypoint::request() opens the fail-open channel inside a KJ_DEFER. That destructor runs while the handler's exception unwinds, so if opening the channel throws, the process terminates. A dynamic Worker with
globalOutbound: nulldoes exactly that: its null outbound throws "not permitted to access the internet" from startRequest().Catch the failure and fail open to a WorkerInterface that rejects with it. The fail-open path then responds with a 500, the same as when the channel opens lazily and the request through it fails, as a channel to another process does.