Skip to content

Detect own-leaked lock on PreconditionFailed in acquire_lock (#2)#67

Open
Darksinian wants to merge 1 commit into
awslabs:mainfrom
reflex-dev:main
Open

Detect own-leaked lock on PreconditionFailed in acquire_lock (#2)#67
Darksinian wants to merge 1 commit into
awslabs:mainfrom
reflex-dev:main

Conversation

@Darksinian
Copy link
Copy Markdown

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.

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.
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.

1 participant