Skip to content

Commit

Permalink
JSRPC: Wait for output gates on incoming and outgoing RPCs.
Browse files Browse the repository at this point in the history
(Tested in internal codebase where some additional utilities are available.)
  • Loading branch information
kentonv committed Apr 26, 2024
1 parent 732e7fe commit 87cb256
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/workerd/api/worker-rpc.c++
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,12 @@ JsRpcPromiseAndPipleine callImpl(

auto& ioContext = IoContext::current();

KJ_IF_SOME(lock, ioContext.waitForOutputLocksIfNecessary()) {
// Replace the client with a promise client that will delay thecall until the output gate
// is open.
client = lock.then([client = kj::mv(client)]() mutable { return kj::mv(client); });
}

auto builder = client.callRequest();

// This code here is slightly overcomplicated in order to avoid pushing anything to the
Expand Down Expand Up @@ -1052,7 +1058,13 @@ public:
js.throwException(kj::mv(error));
})));

return result;
if (ctx.hasOutputGate()) {
return result.then([this]() {
return KJ_REQUIRE_NONNULL(weakIoContext->tryGet()).waitForOutputLocks();
});
} else {
return result;
}
};

switch (op.which()) {
Expand Down

0 comments on commit 87cb256

Please sign in to comment.