-
Notifications
You must be signed in to change notification settings - Fork 333
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
POC of different destinations for rpc and fetch #3402
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Carmen Popoviciu <CarmenPopoviciu@users.noreply.github.com>
The generated output of Full Type Diff |
@@ -663,6 +663,8 @@ struct ExternalServer { | |||
# `HttpOptions`. | |||
|
|||
address @0 :Text; | |||
|
|||
addressFetch @7 :Text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment required, and I think you moved the comment of the above field?
We'll need a test as well |
Can't we do the differentiation in the proxy worker instead? |
I'm guessing this means Wrangler's proxy worker? As far as I know, there's no way to forward on RPC requests from a worker. The proxy worker would have to have logic along the lines of "if HTTP send to worker a, if RPC send to worker b", but I don't know where that could be written. It couldn't go in |
Are you certain a proxy wouldn't work? |
@danlapid Fairly sure—I think this codepath would fail: workerd/src/workerd/io/worker.c++ Lines 1920 to 1950 in 9e915ed
I can definitely give it a quick go though |
@danlapid Having tried it, I can't figure out how to make a Proxy work—not to say it can't, but I can't figure out how. Additionally, I'm not sure doing this in userland is really the right solution here—it feels like this should be a runtime concern (as it is when deployed). If we do it in userland, then anyone else who comes along and wants to build something similar to Workers Assets needs to copy a fairly convoluted proxy worker, compared to just adding a single config property. |
TLDR: This is a quick POC of a way to point RPC calls and HTTP requests to different network addresses.
The problem
Wrangler/Miniflare uses a
workerd
ExternalServer
to represent service bindings between Workers in local development. This is because each Worker runs in a differentworkerd
process configured bywrangler dev
(ignoring the experimental multiworker support we've been landing recently). The caller will configure:as the service binding, where
address
is a direct address to acapnpConnectHost
configuredSocket
from the callee.This means that all communication over that service binding will go to the service linked to the
capnpConnectHost
Socket
on the calleeworkerd
.However, for Workers Assets this presents a problem. Communication over service bindings needs to go to a different Worker depending on whether it's RPC or HTTP (to the user worker and router worker respectively). We need a way to connect to different addresses (Miniflare exposes a
Socket
for every configured worker) based on the type of communication.The proposed solution
This PR implements (with bugs, caveats, and build failures) a proposed solution which adds an additional config property to
ExternalServer
,addressFetch
. When workerd is making a connection to anExternalServer
, it should use the address specified inaddressFetch
for HTTP communication and the address specified inaddress
for RPC communication. IfaddressFetch
is not specified it should useaddress
for both RPC and HTTP communication.Wrangler/Miniflare can then leverage this by pointing
address
at the user worker'sSocket
, andaddressFetch
at the router worker'sSocket