I made a sample repo here https://github.com/threepointone/test-do-ordering, but lemme try to explain.
I have a durable object that looks like this
export class MyDO extends DurableObject {
testThis = 0;
someMethod1() {
console.log("calling someMethod1");
this.testThis = 1;
}
someMethod2() {
console.log("calling someMethod2");
this.testThis = 2;
}
async fetch(request: Request): Promise<Response> {
console.log("calling fetch");
return new Response(this.testThis.toString());
}
}
In my worker's fetch handler, I call this:
const docId = env.MyDO.idFromName(getRandomRoomName());
const stub = env.MyDO.get(docId);
stub.someMethod1(); // note there's no await here
stub.someMethod2(); // note there's no await here
return stub.fetch(request);
(Note the lack of awaits)
The expected behavior:
- The response is
"2"
- order of function calls:
someMethod1, someMethod2, fetch
Actual behaviour varies in test, local dev, and production
- with
npm test (the vitest environment), I get response "2" and the expected ordering:
someMethod1, someMethod2, fetch
- with
npm start (local dev with wrangler), I get response "0", and this ordering:
fetch, someMethod1, someMethod2
- in production (with
npm run deploy), I get "1", and this ordering:
someMethod1, fetch, someMethod2
This feels like a bug (@kentonv I remember you telling me it should preserve E ordering)
I made a sample repo here https://github.com/threepointone/test-do-ordering, but lemme try to explain.
I have a durable object that looks like this
In my worker's fetch handler, I call this:
(Note the lack of awaits)
The expected behavior:
"2"someMethod1,someMethod2,fetchActual behaviour varies in test, local dev, and production
npm test(the vitest environment), I get response"2"and the expected ordering:someMethod1,someMethod2,fetchnpm start(local dev with wrangler), I get response"0", and this ordering:fetch,someMethod1,someMethod2npm run deploy), I get"1", and this ordering:someMethod1,fetch,someMethod2This feels like a bug (@kentonv I remember you telling me it should preserve E ordering)