Skip to content

🐛 Overriding a DO's method prevents it being called via RPC #4499

@threepointone

Description

@threepointone

repro: https://github.com/threepointone/override-do-rpc-method

The setup: A Durable Object class that has a method that is overridden inside its constructor.

class MyDO extends DurableObject {
  constructor(state: DurableObjectState, env: Env) {
    super(state, env);

    const _something = this.something.bind(this);
    this.something = (message: string) => {
      console.log("overriding something");
      return _something(message);
    };
  }
  async something(message: string) {
    return `asked ${message}: hello world`;
  }
}

Nothing fancy, we see that ::something() is overridden inside its constructor.

Let's call it from a worker:

export default {
  async fetch(_request: Request, env: Env, _ctx: ExecutionContext) {
    const id = env.MyDO.idFromName("my-durable-object");
    const myDO = env.MyDO.get(id);
    const res = await myDO.something("anyone there?");
    return new Response(res);
  },
};

Without the override, we get the expected response: asked anyone there?: hello world.

However, with the override, the request doesn't reach the Durable Object, and we get this error:

The RPC receiver does not implement the method "something".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions