Skip to content

Commit e562cc0

Browse files
authored
Merge pull request #5367 from cloudflare/gv/exclusivejoin
containers: Keep doing exclusive join just in case the service request does not exit
2 parents 03800e5 + 0151d3d commit e562cc0

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/workerd/api/container.c++

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,27 @@ class Container::TcpPortWorkerInterface final: public WorkerInterface {
162162
// ... and then adapt that to an HttpService ...
163163
auto service = kj::newHttpService(*client);
164164

165-
// ... and now we can just forward our call to that.
165+
// ... fork connection promises so we can keep the original exception around ...
166+
auto connectionPromiseForked = connectionPromise.fork();
167+
auto connectionPromiseBranch = connectionPromiseForked.addBranch();
168+
auto connectionPromiseToKeepException = connectionPromiseForked.addBranch();
169+
170+
// ... and now we can just forward our call to that ...
166171
try {
167-
co_await service->request(method, noHostUrl, newHeaders, requestBody, response);
172+
co_await service->request(method, noHostUrl, newHeaders, requestBody, response)
173+
.exclusiveJoin(
174+
// never done as we do not want a Connection RPC exiting successfully
175+
// affecting the request
176+
connectionPromiseBranch.then([]() -> kj::Promise<void> { return kj::NEVER_DONE; }));
168177
} catch (...) {
169178
auto exception = kj::getCaughtExceptionAsKj();
170179
connectionException = kj::some(kj::mv(exception));
171180
}
172181

173-
// we prefer an exception from the container service that might've caused
174-
// the error in the first place, that's why we await for the connectionPromise
182+
// ... and last but not least, if the connect() call succeeded but the connection
183+
// was broken, we throw that exception.
175184
KJ_IF_SOME(exception, connectionException) {
176-
co_await connectionPromise;
185+
co_await connectionPromiseToKeepException;
177186
kj::throwFatalException(kj::mv(exception));
178187
}
179188
}

0 commit comments

Comments
 (0)