Repository navigation
fix(tus): release an S3 lock acquired after the request aborts - #1774
Open
xKrishnaSaxena wants to merge 1 commit into
Open
xKrishnaSaxena wants to merge 1 commit into
xKrishnaSaxena wants to merge 1 commit into
Conversation
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.
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.
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 withLockTimeoutbut 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 with503 acquiring lock timeout, because the lock only expires after 15 s.TUS_LOCK_TYPEdefaults topostgres, 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()returnedtruebut the request has aborted,lock()deletes the lock before it rejects withLockTimeout. If the delete fails, the error is logged the same wayunlock()logs it, and the lock falls back to expiring. This matchesPgLock, which throws inside its transaction since #1360, so the rollback frees the advisory lock.Same reproduction as the issue (production locker settings, local RustFS):
Additional context
src/test/s3-locker.test.ts(runs against RustFS): it aborts the request as the acquiring PUT completes, then checks thatlock()rejects withLockTimeoutand 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: passnpm run test:unit: 224 files, 4503 tests passvitest --config vitest.integration.config.ts src/test/s3-locker.test.ts src/test/tus.test.ts src/test/tus-timeout.test.ts: 72 passreleaseLock(id)toreleaseLock(id, leaseToken). If it lands first, the new call needs the token too.