Detect own-leaked lock on PreconditionFailed in acquire_lock (#2)#67
Open
Darksinian wants to merge 1 commit into
Open
Detect own-leaked lock on PreconditionFailed in acquire_lock (#2)#67Darksinian wants to merge 1 commit into
Darksinian wants to merge 1 commit into
Conversation
When boto3 silently retries a PutObject that already succeeded server-side (transient 5xx after write, lost response, connection reset, etc.), the retry returns 412 PreconditionFailed because the lock now exists. The helper previously treated this as "another client holds the lock" and only recovered after the 60s TTL expired. Write a per-call uuid into the lock body. On 412 PreconditionFailed read the existing body — if it matches our token, boto3 must have retried our own successful PUT and we own the lock. Take it via the same delete + re-acquire path the staleness check already uses. Concurrent clients still serialise correctly: each call generates its own uuid, so a foreign client's lock body never matches our token. Callers who also need to recover locks across reinvocations of the helper (e.g. an outer-loop retry of git push) can set GIT_REMOTE_S3_OWNER_TOKEN to a stable per-client value.
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.
When boto3 silently retries a PutObject that already succeeded server-side (transient 5xx after write, lost response, connection reset, etc.), the retry returns 412 PreconditionFailed because the lock now exists. The helper previously treated this as "another client holds the lock" and only recovered after the 60s TTL expired.
This solves the issue by writing a per-call identifier (uuid by default) into the lock body. On 412 PreconditionFailed we read the existing lock and if it matches our token, boto3 must have retried our own successful PUT and we own the lock. Take it via the same delete + re-acquire path the staleness check already uses.
Concurrent clients still serialise correctly: each call generates its own uuid, so a foreign client's lock body never matches our token. Callers who also need to recover locks across reinvocations of the helper (e.g. an outer-loop retry of git push) can set GIT_REMOTE_S3_OWNER_TOKEN to a stable per-client value.