Data Clone Error when returning a Response from an RPC

I have worker A that exposes and endpoint to initialize a websocket connection. I have worker B that holds the durable object for the websocket connection and exposes and RPC entry point method to initialize the websocket. So A calls B via RPC, B replies with a Response including the websocket client. I am getting the data clone error on the websocket response. I am aware RPC have a limitation that they must return serializable objects. My question is, is there any workaround to get this working without having to move the durable object from b to a? Or can I implement serialization and deserialization of the websocket object to bypass the issue?
2 Replies
_.Mass._
_.Mass._OP6mo ago
I'll might give this a try https://developers.cloudflare.com/workers/runtime-apis/rpc/#send-functions-as-parameters-of-rpc-methods and create an RpcTarget class that's returned via RPC and has a method to intialize the websocket
Cloudflare Docs
Remote-procedure call (RPC)
The built-in, JavaScript-native RPC system built into Workers and Durable Objects.
_.Mass._
_.Mass._OP6mo ago
my solution to this in the end was to bind worker B to worker A as both an WorkerEntrypoint and Fetcher. This way I can use the fetcher binding to initiate the websocket connection and the RPC binding for other business related functions.

Did you find this page helpful?