Repository navigation
fix(update): stop sharing in-flight D1 reads across requests - #66205
Conversation
There was a problem hiding this comment.
Looks good. Only settled results are cached now, so concurrent requests stop sharing an in-flight D1 promise. Every caller of cachedRead gets plain data (first() / .results), so caching values instead of promises is safe. A failed read throws before anything is stored, so the next request still retries D1.
I checked that the new concurrency test fails on the base code and that the service's test suite passes with this change (31/31). tsc --noEmit also passes. I couldn't reproduce the actual Workers "different request" I/O error locally, because the tests use a SQLite stand-in for D1.
Public API: unchanged. This only touches the update worker's internal cache.
One trade-off to be aware of: concurrent misses on a cold key now each hit D1, instead of being merged into one query. That only lasts as long as a query takes, once per 60s TTL per isolate, so it seems acceptable.
The update worker cached D1 query promises per isolate, so concurrent lookups shared one in-flight read. Workers binds the D1 result stream to the request that started the query. When a different request ended up reading it, the lookup failed with:
This shows up on hot paths such as
/update/api/latest/cli/npm, where many clients miss the cache at the same moment.cachedReadnow stores only settled results. Concurrent misses each query D1 once, and later requests reuse the result for the same 60s TTL. Failed reads are still not cached, since they throw before the result is stored.Tests:
No feature flag: this is a bug fix.