Workers RPC — Lifecycle · Cloudflare Wor...

Hi all! I'm running into the following error when using Workflows: An RPC stub was not disposed properly. You must call dispose() on all stubs in order to let the other side know that you are no longer using them. You cannot rely on the garbage collector for this because it may take arbitrarily long before actually collecting unreachable objects. As a shortcut, calling dispose() on the result of an RPC call disposes all stubs within it. I see that step.do expects to return Rpc.Serializable<unknown>, so I did a little bit of reading about the RPC lifecycle here and found that in the context of Worker Service Bindings, you should either use the experimental using syntax, or explicitly call object[Symbol.dispose](). I'm a little confused because this error is only thrown after some calls to step.do, and not others. If someone could provide some insight as to what's going on, that would be great. Happy to provide more details also
Cloudflare Docs
Workers RPC — Lifecycle · Cloudflare Workers docs
Memory management, resource management, and the lifecycle of RPC stubs.
6 Replies
Nathan Scheele
Nathan ScheeleOP2w ago
After further debugging, it seems this error is thrown immediately after the step returns a value. Below is the step where this occurs
const orders = await step.do(
"get orders",
async () => {
const orders = await getOrders();
return orders;
}
);
const orders = await step.do(
"get orders",
async () => {
const orders = await getOrders();
return orders;
}
);
getOrders fetches data from an external API and returns the JSON payload
Seekerdasbatatas
does this happen in deployed workers or just local dev?
Nathan Scheele
Nathan ScheeleOP2w ago
I haven't tried deploying it yet, I'm still working locally. Let me try deploying @Seekerdasbatatas Okay, so I don't seem to get the error once deployed. I also noticed that it only happens on the first workflow run after the local server starts or is reset
Seekerdasbatatas
Yhep I'll try to investigate it next week
Nathan Scheele
Nathan ScheeleOP2w ago
Awesome, thanks! While I have you, is there any reference material for returning large amounts of data between steps? I'm running up against the 1MiB limit for RPC return values I've tried returning a ReadableStream from the step, but it just returns undefined
Matt Silverlock
Break it down, or store it in R2.

Did you find this page helpful?