Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix document creation race condition #221

Merged
merged 4 commits into from
Apr 16, 2024

Conversation

paulgb
Copy link
Member

@paulgb paulgb commented Apr 16, 2024

When a client attempts to create a new doc with a given name, we first check if the doc exists and if not we put an empty doc on S3. There is a potential race condition where if two requests check if a doc exists, they will both write an empty file. If the file has since changed, those changes will be erased.

I thought this was mostly theoretical, but I want to rule it out as it seems to be happening.

The fix is that, instead of attempting to create the empty file from the stateless worker, we delegate file creation to the durable object itself. This means instantiating the durable object earlier in the connection lifecycle, but has the advantage that the document will only be created if it does not already exist (since there is guaranteed to only be one instance of the durable object).

Copy link

vercel bot commented Apr 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
y-sweet-debugger ⬜️ Ignored (Inspect) Visit Preview Apr 16, 2024 1:23pm
y-sweet-demos ⬜️ Ignored (Inspect) Visit Preview Apr 16, 2024 1:23pm
y-sweet-gendocs ⬜️ Ignored (Inspect) Visit Preview Apr 16, 2024 1:23pm

@paulgb paulgb marked this pull request as ready for review April 16, 2024 13:25
@paulgb paulgb merged commit 1f5dc63 into main Apr 16, 2024
9 checks passed
@paulgb paulgb deleted the paul/dis-1936-fix-document-creation-race-condition branch April 16, 2024 13:37
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants