Post

I keep running into this annoying AsyncLocalStorage bug in Cloudflare Workers. The value for one of my ALS stores randomly "goes away" lol. I found that the bug showed up a lot when I reused a Drizzle instance across requests (in a Durable Object) - which was a simple fix...

And it also appeared to not like it when I re-used a Map object across requests either - another simple fix... but now I'm seeing the problem again, and this time I have no clue what could be causing it.

0 reposts0 likes

It feels really random - in the sense that (this time, at least) the bug shows itself like 1 in 25 requests to a particular endpoint. The endpoint in question is a batched tRPC call where the first 2 procedures work totally fine, but the 3rd gets undefined when calling getStore (where I then throw).

The ALS value is being set well before the call to our http router (hono) and the tRPC router itself. And it's the ONLY time the value is ever being set. Months ago I attempted to create a minimal reproduction of the bug but all my attempts failed.

@jasnell.me @kentonvarda.com Are you aware of any issue like this? I wanted my reach-out to be a last resort... but I think I'm hit my limit of what I'm able to do. In the past it's been possible to replicate locally (although far less frequently), but so far this time I haven't been able to.