Skip to content

Commit 87cb256

Browse files
committed
JSRPC: Wait for output gates on incoming and outgoing RPCs.
(Tested in internal codebase where some additional utilities are available.)
1 parent 732e7fe commit 87cb256

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/workerd/api/worker-rpc.c++

+13-1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ JsRpcPromiseAndPipleine callImpl(
467467

468468
auto& ioContext = IoContext::current();
469469

470+
KJ_IF_SOME(lock, ioContext.waitForOutputLocksIfNecessary()) {
471+
// Replace the client with a promise client that will delay thecall until the output gate
472+
// is open.
473+
client = lock.then([client = kj::mv(client)]() mutable { return kj::mv(client); });
474+
}
475+
470476
auto builder = client.callRequest();
471477

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

1055-
return result;
1061+
if (ctx.hasOutputGate()) {
1062+
return result.then([this]() {
1063+
return KJ_REQUIRE_NONNULL(weakIoContext->tryGet()).waitForOutputLocks();
1064+
});
1065+
} else {
1066+
return result;
1067+
}
10561068
};
10571069

10581070
switch (op.which()) {

0 commit comments

Comments
 (0)