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

JSRPC: Guard wildcard method behind feature flag. #1864

Merged
merged 1 commit into from
Mar 19, 2024
Merged
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
25 changes: 25 additions & 0 deletions src/workerd/api/http.c++
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,31 @@ kj::Maybe<jsg::Ref<JsRpcProperty>> Fetcher::getRpcMethod(jsg::Lock& js, kj::Stri
// This is like JsRpcStub::getRpcMethod(), but we also initiate a whole new JS RPC session
// each time the method is called (handled by `getClientForOneCall()`, below).

auto flags = FeatureFlags::get(js);
if (!flags.getFetcherRpc() && !flags.getWorkerdExperimental()) {
// We need to pretend that we haven't implemented a wildcard property, as unfortunately it
// breaks some workers in the wild. We would, however, like to warn users who are trying to use
// RPC so they understand why it isn't working.

if (name == "idFromName") {
// HACK specifically for itty-durable: We will not write any warning here, since itty-durable
// automatically checks for this property on all bindings in an effort to discover Durable
// Object namespaces. The warning would be confusing.
//
// Reported here: https://github.com/kwhitley/itty-durable/issues/48
} else {
IoContext::current().logWarningOnce(kj::str(
"WARNING: Tried to access method or property '", name, "' on a Service Binding or "
"Durable Object stub. Are you trying to use RPC? If so, please enable the 'rpc' compat "
"flag or update your compat date to 2024-04-03 or later (see "
"https://developers.cloudflare.com/workers/configuration/compatibility-dates/ ). If you "
"are not trying to use RPC, please note that in the future, this property (and all other "
"property names) will appear to be present as an RPC method."));
}

return kj::none;
}

// Do not return a method for `then`, otherwise JavaScript decides this is a thenable, i.e. a
// custom Promise, which will mean a Promise that resolves to this object will attempt to chain
// with it, which is not what you want!
Expand Down
9 changes: 9 additions & 0 deletions src/workerd/io/compatibility-date.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,13 @@ struct CompatibilityFlags @0x8f8c1b68151b6cef {
$compatEnableFlag("unwrap_custom_thenables")
$compatDisableFlag("no_unwrap_custom_thenables")
$compatEnableDate("2024-04-01");

fetcherRpc @46 :Bool
$compatEnableFlag("rpc")
$compatDisableFlag("no_rpc")
$compatEnableDate("2024-04-03");
# Whether the type `Fetcher` type -- which is the type of Service Bindings, and also the parent
# type of Durable Object stubs -- support RPC. If so, this type will have a wildcard method, so
# it will appear that all possible property names are present on any fetcher instance. This could
# break code that tries to infer types based on the presence or absence of methods.
}
Loading