Skip to content

A repeated claim that fails before pg_try_advisory_lock still unlocks the key #39

Closed

Description

@vheathen

A repeated claim that fails before pg_try_advisory_lock runs still unlocks the key. An owner claims again after an earlier claim finished past its caller's 15 s timeout; with defaults that needs several queued claims that each end under 15 s, otherwise a lock_timeout or statement_timeout below 15 s set through :parameters. If that repeated claim then fails early (such a timeout while a table lock on subscriptions is held, or a pg_cancel_backend of the waiting claim), it still runs the unlock: the server keeps the owner's record while PostgreSQL holds nothing, and another session's claim succeeds. Shown on the lock server API in 12 of 12 cases, 3 of them reaching the repeated claim through a claim that outlived a 2.5 s caller timeout, with lock_timeout 1 s; at 19072b4 the hold stayed. Very low with defaults, low where lock_timeout or statement_timeout is set below 15 s.

Part of the review of main at 1f9d1f8: #27 (comment)

Activity

  1. yordis commented on Oct 27, 2026

    @yordis
    Member

    Fixed by #60. A repeated claim that fails before pg_try_advisory_lock runs no longer unlocks the key its owner still holds.

    Verified with test/advisory_locks_test.exs ("should keep the lock held when a repeated claim cannot wait for a table lock" and "should keep the lock held when a repeated claim is cancelled while it waits"): both fail against the code before #60 and pass on main.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions