Repository navigation
Conversation
A Durable Object is single-threaded, but async awaits let different requests interleave. The user_data flow reads the full JSON, mutates it, then overwrites it wholesale; two concurrent requests could clobber each other's updates. Queue each UserDO.fetch through a promise chain so the entire business operation (including Sub-Store HTTP requests and cron refreshes) runs to completion before the next one starts. A failed request does not jam the queue. Add regression tests that assert the operation sequence stays strictly serialized and that a failed request does not block later ones.
Add a real read-modify-write regression: two concurrent Sub-Store download requests each read the whole user_data blob, await script execution, then write it back. With the queue both updates survive; a control test via _handleFetch bypasses the queue and demonstrates the test catches the loss. Also fix the storage mock to join all tagged-template parts: the real SQL atom uses multi-line templates, so the old mock matched nothing. Wire the regression suite into CI (Workers job).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A Durable Object is single-threaded, but
awaitlets requests interleave. Theuser data flow reads the whole JSON blob, mutates it, then overwrites it. Two
concurrent requests could clobber each other's updates.
UserDO.fetchnow queues each request through a promise chain, so the wholeoperation (including Sub-Store HTTP requests and cron refreshes) runs to
completion before the next one starts. A failed request does not jam the queue.
Tests
user_data, await,then write back. Both updates survive with the queue in place.
_handleFetchand confirms the testcatches the lost-update case.
the first part and never matched the real multi-line SQL.
The Workers CI job now runs these Node tests.
Part of the split from the original combined PR.