You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(storage): concurrent duplicate reservations can both succeed #281
Storage.createUpload() checks for an existing upload with a SELECT and then INSERTs, with no transaction and no unique constraint. The only index on uploads is the non-unique idx_uploads_key_version on (key, version).
Two CreateCacheEntry calls for the same key, version, scope and repo that arrive at the same moment can both pass the check, so both get 200 and a signed upload URL. #277 returns 409 already_exists for a duplicate, but only when the requests don't overlap. Parallel BuildKit jobs writing the same cache key (#276) are the clients most likely to overlap.
Proposed fix
Migration: add a unique index on uploads (key, version, scope, repoId). Deduplicate existing rows first, keeping the newest upload per tuple, or the migration fails on databases that already have duplicates.
createUpload(): insert directly and map the unique-violation error from SQLite, Postgres and MySQL to AlreadyExistsError. The pre-check SELECT then becomes unnecessary.
Test: fire several CreateCacheEntry calls for the same key concurrently and assert exactly one 200, with every other call getting 409. Run it across the test:matrix DB drivers.
Activity