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

🚀 Feature Request:RPC Support for Durable Objects in wrangler dev #5918

Open
yawnt opened this issue May 25, 2024 · 14 comments
Open

🚀 Feature Request:RPC Support for Durable Objects in wrangler dev #5918

yawnt opened this issue May 25, 2024 · 14 comments
Assignees
Labels
enhancement New feature or request miniflare Relating to Miniflare

Comments

@yawnt
Copy link

yawnt commented May 25, 2024

Describe the solution

When binding a durable object using RPC that was defined in a different worker, it fails with:

Cannot access `MyDurableObject#myMethod` as Durable Object RPC is not yet supported between multiple `wrangler dev` sessions.

This is really useful when using durable objects in combination with wrangler pages dev since, as far as I understand, you cannot deploy a worker from a Pages project.

@yawnt yawnt added the enhancement New feature or request label May 25, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk May 25, 2024
@petebacondarwin
Copy link
Contributor

Can you try extending the DurableObject class in your code, which may resolve this problem. JS RPC entry points must derive from either DurableObject or WorkerEntrypoint.

@petebacondarwin petebacondarwin added the awaiting reporter response Needs clarification or followup from OP label Jun 24, 2024
@robbertvanginkel
Copy link

robbertvanginkel commented Jun 24, 2024

Extending DurableObject does not fix this. The current behaviour as reported here is part of the test suite on current main, which indicates this would only be supported in the future: e469fb9 /

test("should support binding to Durable Object in another worker", async ({
dev,
}) => {
// RPC isn't supported in this case yet :(
await dev({
"wrangler.toml": dedent`
name = "bound"
main = "index.ts"
[durable_objects]
bindings = [
{ name = "OBJECT", class_name = "ThingObject" }
]
`,
"index.ts": dedent`
import { DurableObject } from "cloudflare:workers";
export class ThingObject extends DurableObject {
fetch(request) {
return new Response(\`\${request.method} \${request.url} \${JSON.stringify(request.cf)}\`);
}
get property() {
return "property:ping";
}
method() {
return "method:ping";
}
};
export default {}; // Required to treat as modules format worker
`,
});
const { url } = await dev({
"wrangler.toml": dedent`
name = "entry"
main = "index.ts"
[durable_objects]
bindings = [
{ name = "OBJECT", class_name = "ThingObject", script_name = "bound" }
]
`,
"index.ts": dedent`
export default {
async fetch(request, env, ctx) {
const id = env.OBJECT.newUniqueId();
const stub = env.OBJECT.get(id);
const { pathname } = new URL(request.url);
if (pathname === "/rpc") {
const errors = [];
try { await stub.property; } catch (e) { errors.push(e); }
try { await stub.method(); } catch (e) { errors.push(e); }
return Response.json(errors.map(String));
}
return stub.fetch("https://placeholder:9999/", {
method: "POST",
cf: { thing: true },
});
}
}
`,
});
await waitFor(async () => {
const response = await fetch(url);
const text = await response.text();
// Check protocol, host, and cf preserved
expect(text).toBe('POST https://placeholder:9999/ {"thing":true}');
});
const rpcResponse = await fetch(new URL("/rpc", url));
const errors = await rpcResponse.json();
expect(errors).toMatchInlineSnapshot(`
[
"Error: Cannot access \`ThingObject#property\` as Durable Object RPC is not yet supported between multiple \`wrangler dev\` sessions.",
"Error: Cannot access \`ThingObject#method\` as Durable Object RPC is not yet supported between multiple \`wrangler dev\` sessions.",
]
`);
});

@petebacondarwin
Copy link
Contributor

OK thanks for the clarification. I wasn't sure if it had been fixed already. I'll add it to the backlog.

@petebacondarwin petebacondarwin removed the awaiting reporter response Needs clarification or followup from OP label Jun 24, 2024
@petebacondarwin petebacondarwin moved this from Untriaged to Selected for Development in workers-sdk Jun 24, 2024
@petebacondarwin petebacondarwin added the miniflare Relating to Miniflare label Jun 24, 2024
@Chinoman10
Copy link

I can also confirm this... been struggling for over a week now, causing project delays because of this...
And even if I deploy I'm unable to test this since I can't bind the DO to the Pages project (it's the only DO that doesn't appear in the bindings list, despite being deployed like all others).

@lrapoport-cf lrapoport-cf moved this from Selected for Development to Backlog in workers-sdk Aug 19, 2024
@alexturpin
Copy link

Hey folks just chiming in with more support for this! I'm already using cross-worker RPC calls in dev, was surprised to see it didn't work on Durable Objects! Everything else is very lovely to work with, this would be the cherry on top!

@LilaRest
Copy link

LilaRest commented Oct 4, 2024

Hey @alexturpin! Any updates or ETA for that feature?

@alexturpin
Copy link

@LilaRest sorry for the confusion, I'm not a Cloudflare employee, was just saying I would also find this very useful!

@LilaRest
Copy link

LilaRest commented Oct 4, 2024

@alexturpin My bad, I'm quite tired and realize that I've sent the message in the wrong ticket mentioning the wrong person ^^ Thanks anyway for taking time to answer.

@zhihengGet
Copy link

Any update guys ? this is bad DX :(

@sassanh
Copy link

sassanh commented Oct 18, 2024

Currently, I have to deploy the worker (fast) and my next-on-pages project (slow) to test the even very small changes as long as the change has anything to do with the connection of these two and it slows the development process by an order of magnitude.

If this is going to be like this for a long time, I need to do something about it, so it would be nice if someone could provide an ETA.

A workaround would be also appreciated. If there is a hidden experimental implementation, etc., please let us know. Dealing with an unstable solution would be preferred than waiting 3-4 minutes to test a small iteration.

@grokwich
Copy link

+1

@RamIdeas RamIdeas self-assigned this Oct 25, 2024
@RamIdeas RamIdeas moved this from Backlog to In Progress in workers-sdk Oct 25, 2024
@RamIdeas RamIdeas moved this from In Progress to In Review in workers-sdk Oct 25, 2024
@RamIdeas RamIdeas moved this from In Review to In Progress in workers-sdk Oct 25, 2024
@gregory
Copy link

gregory commented Oct 27, 2024

OK thanks for the clarification. I wasn't sure if it had been fixed already. I'll add it to the backlog.

Hello! Could you share an update on this please? :)
I just landed on this issue.

@petebacondarwin
Copy link
Contributor

@gregory - see #7098

@threepointone
Copy link
Contributor

A workaround is to use .fetch() on the durable object instead of rpc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request miniflare Relating to Miniflare
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.