Skip to content

fix(tus): release an S3 lock acquired after the request aborts - #1774

Open
xKrishnaSaxena wants to merge 1 commit into
supabase:masterfrom
xKrishnaSaxena:fix/s3-lock-release-on-abort
Open

xKrishnaSaxena wants to merge 1 commit into
supabase:masterfrom
xKrishnaSaxena:fix/s3-lock-release-on-abort

Conversation

@xKrishnaSaxena

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Closes #1773

With TUS_LOCK_TYPE=s3, a request that aborts while its lock PUT is in flight can still create the lock object. S3Lock.lock() then rejects with LockTimeout but leaves the object in S3. Nobody owns it, so nothing renews or deletes it. The next request for the same upload waits about 11.5 s and fails with 503 acquiring lock timeout, because the lock only expires after 15 s.

TUS_LOCK_TYPE defaults to postgres, and the window is one PUT round trip, so this is rare, but when it hits, the client's next resume fails with 503.

What is the new behavior?

If acquireLock() returned true but the request has aborted, lock() deletes the lock before it rejects with LockTimeout. If the delete fails, the error is logged the same way unlock() logs it, and the lock falls back to expiring. This matches PgLock, which throws inside its transaction since #1360, so the rollback frees the advisory lock.

Same reproduction as the issue (production locker settings, local RustFS):

master:       aborted request: LockTimeout
              next request: LockTimeout after 11471 ms
this branch:  aborted request: LockTimeout
              next request: acquired after 6 ms

Additional context

  • The signal is still not passed to the PUT. Aborting an in-flight conditional PUT leaves its outcome unknown, so the object could still be created and nothing would know to delete it. Checking after the PUT returns is the only point where we know we own the object.
  • New test in src/test/s3-locker.test.ts (runs against RustFS): it aborts the request as the acquiring PUT completes, then checks that lock() rejects with LockTimeout and that the lock object is gone. On master it fails (promise resolved "{ …(9) }" instead of rejecting: the GET finds the leftover lock).
  • npm run lint, npx tsc --noEmit, npm run build: pass
  • npm run test:unit: 224 files, 4503 tests pass
  • vitest --config vitest.integration.config.ts src/test/s3-locker.test.ts src/test/tus.test.ts src/test/tus-timeout.test.ts: 72 pass
  • fix(tus): fence stale S3 lock leases #1546 changes releaseLock(id) to releaseLock(id, leaseToken). If it lands first, the new call needs the token too.

When the request aborts while the conditional PUT that creates the lock
is in flight, the PUT can still succeed. S3Lock.lock() then rejects with
LockTimeout but leaves the lock object in S3. No one holds it, so no one
renews or unlocks it, and the next request for the upload retries for
about 11.5 s and fails with LockTimeout, because the lock only expires
after 15 s.

Delete the lock before rejecting, as PgLock already does by rolling
back its transaction.
@xKrishnaSaxena
xKrishnaSaxena requested a review from a team as a code owner November 28, 2026 22:42

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUS S3 locker leaves the lock behind when the request aborts during lock acquisition

1 participant