Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Durable Object RPC stub (name interceptor) #1311

Merged
merged 1 commit into from
Dec 16, 2023
Merged

Conversation

MellowYarker
Copy link
Contributor

@MellowYarker MellowYarker commented Oct 17, 2023

This is the client-side work that modifies DO client stubs, enabling them to intercept dynamic method names (those which are not defined on the C++ class).

The server-side PR will fill in the RPC branch of getNamed(), this commit just provides an interface and ensures "legacy" DO stub usage isn't broken.


This is currently pointing to the jsg-named-intercept branch so the diff isn't annoying to look at. My plan is to rebase #1028 on this branch and delete most of the client side (actor.h/c++) stuff from that PR. Really, the only client side changes in that PR should be moving the body of getRpcAndCallRemote() into getNamed().

I'll be adding an internal test to confirm we can call stub.foo() if the compat flag is present, and perhaps more importantly, we can't without it (current stub behavior retained by default).

@MellowYarker MellowYarker changed the title [WIP]Durable Object RPC stub (name interceptor) [WIP] Durable Object RPC stub (name interceptor) Oct 17, 2023
@MellowYarker MellowYarker marked this pull request as draft October 17, 2023 12:49
@jasnell jasnell force-pushed the jsnell/jsg-named-intercept branch 2 times, most recently from 98fbb3d to ac94f6b Compare October 17, 2023 20:27
@MellowYarker MellowYarker force-pushed the milan/js-rpc-stub branch 2 times, most recently from 5115f50 to a9c0fd5 Compare October 19, 2023 15:04
@jasnell jasnell force-pushed the jsnell/jsg-named-intercept branch 2 times, most recently from ba7c284 to e8bf535 Compare October 19, 2023 15:40
src/workerd/api/actor.h Outdated Show resolved Hide resolved
@MellowYarker MellowYarker force-pushed the milan/js-rpc-stub branch 2 times, most recently from e859098 to d3eee51 Compare October 20, 2023 21:02
@MellowYarker
Copy link
Contributor Author

Ah, almost forgot we want to prevent calling certain registered names (like alarm). Will add this just need to find the list of names.

@MellowYarker MellowYarker force-pushed the milan/js-rpc-stub branch 4 times, most recently from 6cd20c9 to 1715a12 Compare October 26, 2023 17:30
@MellowYarker MellowYarker marked this pull request as ready for review October 26, 2023 17:35
@MellowYarker MellowYarker requested review from a team as code owners October 26, 2023 17:35
@MellowYarker MellowYarker requested review from mikea and byule and removed request for a team and mikea October 26, 2023 17:35
@MellowYarker MellowYarker requested review from kentonv and removed request for byule October 26, 2023 17:35
@MellowYarker MellowYarker changed the title [WIP] Durable Object RPC stub (name interceptor) Durable Object RPC stub (name interceptor) Oct 26, 2023
@MellowYarker MellowYarker changed the base branch from jsnell/jsg-named-intercept to main October 26, 2023 19:03
@MellowYarker MellowYarker requested a review from a team as a code owner October 26, 2023 19:03
Copy link
Contributor

@bcaimano bcaimano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The impl seems reasonable, most of my comments are around structuring this PR to land incrementally!

src/workerd/api/actor.h Outdated Show resolved Hide resolved
src/workerd/api/actor.h Outdated Show resolved Hide resolved
src/workerd/api/actor.h Outdated Show resolved Hide resolved
src/workerd/api/actor.h Outdated Show resolved Hide resolved
src/workerd/api/actor.h Outdated Show resolved Hide resolved
src/workerd/api/actor.h Outdated Show resolved Hide resolved
return kj::none;
}

// WARNING: Adding a new method to the Durable Object stub can conflict with RPC method names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning applies to adding methods to Fetcher too, right? Since it is inherited?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it will apply to any type that uses JSG_NAMED_INTERCEPT. But as mentioned in the other comment, we can tweak how this works by changing the flags we use to register the intercept callbacks. The current choice was made in an attempt to make it possible for existing jsg objects to continue to use the other macros easily (JSG_METHOD, JSG_*_PROPERTY, etc) while also supporting interception. But we have the freedom to change how the intercept works right now.

src/workerd/api/actor.h Outdated Show resolved Hide resolved
src/workerd/io/compatibility-date.capnp Outdated Show resolved Hide resolved
src/workerd/api/actor.h Outdated Show resolved Hide resolved
@MellowYarker MellowYarker force-pushed the milan/js-rpc-stub branch 2 times, most recently from 5a24d78 to 9b3c93b Compare October 30, 2023 18:44
src/workerd/api/actor.h Outdated Show resolved Hide resolved
@MellowYarker MellowYarker force-pushed the milan/js-rpc-stub branch 2 times, most recently from f804960 to 2e76dbf Compare November 3, 2023 14:05
src/workerd/api/actor.h Outdated Show resolved Hide resolved
src/workerd/api/tests/actor-stub-test.js Outdated Show resolved Hide resolved
@bcaimano
Copy link
Contributor

bcaimano commented Nov 3, 2023

Looks like you'll need approval from @cloudflare/wrangler as well fyi

@MellowYarker
Copy link
Contributor Author

Looks like you'll need approval from https://github.com/orgs/cloudflare/teams/wrangler as well fyi

Is there a way to replace this group? I wouldn't expect them to review this and I seem to be unable to remove the review request.

@mrbbot
Copy link
Contributor

mrbbot commented Nov 8, 2023

Looks like Wrangler's review request came from src/workerd/tools/api-encoder.c++, which is used in the automatic type generation. We're planning on replacing this soonish, so hopefully won't be a problem in the future. 👍

This is the client-side work that modifies DO client stubs, enabling
them to intercept dynamic method names (those which are not defined on
the C++ class).

The server-side PR will fill in the RPC branch of getNamed(), this
commit just provides an interface and ensures "legacy" DO stub usage
isn't broken.
@MellowYarker
Copy link
Contributor Author

https://github.com/cloudflare/workerd/compare/54b85d24528f9013d34a864f241c8e771fd8358d..244f9216b7c892d4227312e5cd42abb9956b3a0e is a rebase. I also dropped an include in actor.h that wasn't necessary.

@MellowYarker MellowYarker merged commit dc717bc into main Dec 16, 2023
11 checks passed
@MellowYarker MellowYarker deleted the milan/js-rpc-stub branch December 16, 2023 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants