Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build/deps/gen/deps.MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ bazel_dep(name = "brotli", version = "1.2.1")
# capnp-cpp
http.archive(
name = "capnp-cpp",
sha256 = "c8eed3eccf8f839dcea831818e72e03c78a0f5ab4c458497fa380fd007797c57",
strip_prefix = "capnproto-capnproto-2d48111/c++",
sha256 = "4cc9c1efd0310ce82899612df6439c9e401f896c538e07ba9e3990ac8d8c62f4",
strip_prefix = "capnproto-capnproto-a122ef9/c++",
type = "tgz",
url = "https://github.com/capnproto/capnproto/tarball/2d481112f6fdab63c8e557ddcb8323a9c6d5733d",
url = "https://github.com/capnproto/capnproto/tarball/a122ef9a31db579544ad421c7ec412568bce8e7b",
)
use_repo(http, "capnp-cpp")

Expand Down
7 changes: 3 additions & 4 deletions src/workerd/api/restore.c++
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ kj::Promise<WorkerInterface::CustomEvent::Result> RestoreRpcStubCustomEvent::run
auto [donePromise, doneFulfiller] = kj::newPromiseAndFulfiller<void>();

capFulfiller->fulfill(
capnp::membrane(kj::mv(cap), kj::refcounted<CompletionMembrane>(kj::mv(doneFulfiller))));
capnp::membrane(kj::mv(cap), kj::rc<CompletionMembrane>(kj::mv(doneFulfiller))));

// `donePromise` resolves once there are no longer any capabilities pointing between the client
// and server as part of this session.
Expand Down Expand Up @@ -517,11 +517,10 @@ kj::Promise<WorkerInterface::CustomEvent::Result> RestoreRpcStubCustomEvent::sen

rpc::JsRpcTarget::Client cap = sent.getTarget();

cap = capnp::membrane(kj::mv(cap), kj::refcounted<RevokerMembrane>(kj::mv(revokePaf.promise)));
cap = capnp::membrane(kj::mv(cap), kj::rc<RevokerMembrane>(kj::mv(revokePaf.promise)));

auto completionPaf = kj::newPromiseAndFulfiller<void>();
cap = capnp::membrane(
kj::mv(cap), kj::refcounted<CompletionMembrane>(kj::mv(completionPaf.fulfiller)));
cap = capnp::membrane(kj::mv(cap), kj::rc<CompletionMembrane>(kj::mv(completionPaf.fulfiller)));

capFulfiller->fulfill(kj::mv(cap));

Expand Down
17 changes: 6 additions & 11 deletions src/workerd/api/worker-rpc.c++
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ jsg::JsValue deserializeRpcReturnValue(jsg::Lock& js,
// A membrane which attaches some object until it is destroyed.
//
// TODO(cleanup): This is generally useful, should it be part of capnp?
class AttachmentMembrane final: public capnp::MembranePolicy, public kj::Refcounted {
class AttachmentMembrane final: public capnp::MembranePolicy {
public:
explicit AttachmentMembrane(kj::Own<void> attachment): attachment(kj::mv(attachment)) {}

Expand All @@ -386,10 +386,6 @@ class AttachmentMembrane final: public capnp::MembranePolicy, public kj::Refcoun
return kj::none;
}

kj::Own<MembranePolicy> addRef() override {
return kj::addRef(*this);
}

private:
kj::Own<void> attachment;
};
Expand Down Expand Up @@ -1816,8 +1812,8 @@ void JsRpcStub::serialize(jsg::Lock& js, jsg::Serializer& serializer) {
// to getClient() will force it to be created, invoking the restore chain, just so the stub
// can be sent over RPC. Maybe we should actually leave it null and leave it up to the
// receiving end to invoke the restore chain if desired?
auto cap = capnp::membrane(
getClient(), kj::refcounted<AttachmentMembrane>(ioctx.registerPendingEvent()));
auto cap =
capnp::membrane(getClient(), kj::rc<AttachmentMembrane>(ioctx.registerPendingEvent()));

// If a channel is present, send a channel token for it.
kj::Maybe<kj::OneOf<kj::Array<byte>, kj::Promise<kj::Array<byte>>>> channelToken;
Expand Down Expand Up @@ -3499,7 +3495,7 @@ kj::Promise<WorkerInterface::CustomEvent::Result> JsRpcSessionCustomEvent::run(
auto [donePromise, doneFulfiller] = kj::newPromiseAndFulfiller<void>();

capFulfiller->fulfill(capnp::membrane(
revocableTarget.getClient(), kj::refcounted<CompletionMembrane>(kj::mv(doneFulfiller))));
revocableTarget.getClient(), kj::rc<CompletionMembrane>(kj::mv(doneFulfiller))));

// `donePromise` resolves once there are no longer any capabilities pointing between the client
// and server as part of this session.
Expand Down Expand Up @@ -3549,7 +3545,7 @@ kj::Promise<WorkerInterface::CustomEvent::Result> JsRpcSessionCustomEvent::sendR

rpc::JsRpcTarget::Client cap = sent.getTopLevel();

cap = capnp::membrane(kj::mv(cap), kj::refcounted<RevokerMembrane>(kj::mv(revokePaf.promise)));
cap = capnp::membrane(kj::mv(cap), kj::rc<RevokerMembrane>(kj::mv(revokePaf.promise)));

// When no more capabilities exist on the connection, we want to proactively cancel the RPC.
// This is needed in particular for the case where the client is dropped without making any calls
Expand All @@ -3562,8 +3558,7 @@ kj::Promise<WorkerInterface::CustomEvent::Result> JsRpcSessionCustomEvent::sendR
// TODO(cleanup): It feels like there's something wrong with the design here. Can we make this
// less ugly?
auto completionPaf = kj::newPromiseAndFulfiller<void>();
cap = capnp::membrane(
kj::mv(cap), kj::refcounted<CompletionMembrane>(kj::mv(completionPaf.fulfiller)));
cap = capnp::membrane(kj::mv(cap), kj::rc<CompletionMembrane>(kj::mv(completionPaf.fulfiller)));

this->capFulfiller->fulfill(kj::mv(cap));

Expand Down
5 changes: 2 additions & 3 deletions src/workerd/io/trace-stream.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1149,11 +1149,10 @@ kj::Promise<WorkerInterface::CustomEvent::Result> TailStreamCustomEvent::sendRpc

rpc::TailStreamTarget::Client cap = sent.getTopLevel();

cap = capnp::membrane(kj::mv(cap), kj::refcounted<RevokerMembrane>(kj::mv(revokePaf.promise)));
cap = capnp::membrane(kj::mv(cap), kj::rc<RevokerMembrane>(kj::mv(revokePaf.promise)));

auto completionPaf = kj::newPromiseAndFulfiller<void>();
cap = capnp::membrane(
kj::mv(cap), kj::refcounted<CompletionMembrane>(kj::mv(completionPaf.fulfiller)));
cap = capnp::membrane(kj::mv(cap), kj::rc<CompletionMembrane>(kj::mv(completionPaf.fulfiller)));

capFulfiller->fulfill(kj::mv(cap));

Expand Down
12 changes: 2 additions & 10 deletions src/workerd/util/completion-membrane.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace workerd {
// fulfills a fulfiller.
//
// TODO(cleanup): This is generally useful, should it be part of capnp?
class CompletionMembrane final: public capnp::MembranePolicy, public kj::Refcounted {
class CompletionMembrane final: public capnp::MembranePolicy {
Comment thread
mikea marked this conversation as resolved.
public:
explicit CompletionMembrane(kj::Own<kj::PromiseFulfiller<void>> doneFulfiller)
: doneFulfiller(kj::mv(doneFulfiller)) {}
Expand All @@ -26,10 +26,6 @@ class CompletionMembrane final: public capnp::MembranePolicy, public kj::Refcoun
return kj::none;
}

kj::Own<MembranePolicy> addRef() override {
return kj::addRef(*this);
}

void reject(kj::Exception&& e) {
doneFulfiller->reject(kj::mv(e));
}
Expand All @@ -41,7 +37,7 @@ class CompletionMembrane final: public capnp::MembranePolicy, public kj::Refcoun
// A membrane which revokes when some Promise is fulfilled.
//
// TODO(cleanup): This is generally useful, should it be part of capnp?
class RevokerMembrane final: public capnp::MembranePolicy, public kj::Refcounted {
class RevokerMembrane final: public capnp::MembranePolicy {
public:
explicit RevokerMembrane(kj::Promise<void> promise): promise(promise.fork()) {}

Expand All @@ -61,10 +57,6 @@ class RevokerMembrane final: public capnp::MembranePolicy, public kj::Refcounted
return kj::none;
}

kj::Own<MembranePolicy> addRef() override {
return kj::addRef(*this);
}

kj::Maybe<kj::Promise<void>> onRevoked() override {
return promise.addBranch();
}
Expand Down
Loading