Repository navigation
Conversation
…llide
`write_inbound` picks a free path with `_unique_inbound_path` (an existence
check) and only then uploads to it. Both steps await, so two concurrent
uploads whose timestamped names collide can observe the same free candidate
and write to the same key — both calls succeed and return the same path, and
the first upload's bytes are silently lost.
Guard allocate+write with a per-workspace lock so a colliding upload sees the
file its predecessor just wrote and takes the `-{n}` suffix instead.
The regression test drives two concurrent uploads of `report.txt` with
different payloads and asserts they get distinct paths and keep their own
bytes; it fails on the current code with a single shared path.
This branch has not been deployed
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.
Fixes #1889.
Problem
write_inboundallocates a destination and writes to it in two separate awaits:_unique_inbound_pathonly looks for a free name, it does not reserve one.Two requests that arrive within the same second build the same
{unix_ts}_{display}name, both observe the candidate as absent, and bothupload to it. Both responses succeed and carry the same path, but only the
second payload survives — one document is lost. The dashboard uploads several
attachments concurrently, so this is reachable from the UI.
Fix
Allocate and write under a per-workspace
asyncio.Lock, so a colliding uploadobserves the file its predecessor just wrote and picks the existing
{stem}-{n}{suffix}fallback. The lock is cached per workspace directory andrebuilt when the running event loop changes, so a module-level cache never
hands a lock bound to a closed loop to a new one.
Tests
tests/unit/gateway/test_inbound_store.pygainstest_concurrent_same_name_uploads_keep_their_own_bytes, which uploads twodifferent payloads named
report.txtconcurrently and asserts two distinctpaths whose contents are the two original payloads.
Before the fix the test fails on the shared path:
After the fix: