DO: List after non-awaited put returns empty on first request
When run via wrangler dev, the output is correct. When run on Miniflare 1, the very first request returns an empty list (subsequent requests are handled correctly). If you change the put to await then it works correctly but the await shouldn't be needed. Miniflare 2 doesn't have a problem here AFAICT
interface Env {
TEST: DurableObjectNamespace
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const id = env.TEST.idFromName('some test')
const stub = env.TEST.get(id)
return stub.fetch(`http://local?value=${(Math.random() * 100).toFixed(0)}`)
}
}
export class Durable {
state: DurableObjectState
constructor(state: DurableObjectState, env: Env) {
this.state = state
}
async fetch(request: Request): Promise<Response> {
const { searchParams } = new URL(request.url)
this.state.storage.put('x', searchParams.get('value'))
const l = Array.from((await this.state.storage.list()).entries())
return new Response(searchParams.get('value') + ': ' + JSON.stringify(l), { status: 200 })
}
}
Hey! 👋 Miniflare 1 implements the old-style of Durable Objects, without input/output gates or write coalescing. Once Miniflare 2 has been released, it might be worth backporting some of its changes to Miniflare 1, so people can continue to use that if needed.
Hmmm... this didn't seem like a gates/coalescing issue. Why is only the first put invisible to the next list but subsequent puts show up just fine?
It's not actually a big deal for us. I just await the put in our code to workaround this and my code will eventually change to not need the list after put.