fix(partition-keys): make claim_slot non-blocking under concurrent lease DML
Severity
Medium — worker liveness / head-of-line blocking.
Problem
The partition-key contract says a busy claim_slot returns NULL so a worker can immediately try another slot. The implementation uses blocking SELECT ... FOR UPDATE on pgque.partition_slot.
If another transaction is claiming, renewing, receiving, or acknowledging that slot, the caller waits on the row lock instead of being steered onward.
Reproduction
- Session A begins, calls
claim_slot, and leaves the transaction open. - Session B sets
statement_timeout = '750ms'and callsclaim_slotfor the same slot.
Observed:
ERROR: canceling statement due to statement timeout
CONTEXT: while locking tuple ... in relation "partition_slot"
Affected implementation: devel/sql/pgque-api/partition_keys.sql, claim_slot.
An infinite lease TTL is also currently accepted on PostgreSQL 19, which can make a crashed slot permanently unavailable.
Expected fix
Use a non-blocking row-lock transition (FOR UPDATE SKIP LOCKED / NOWAIT or equivalent) and return NULL for a currently locked/busy slot while still distinguishing an unsubscribed slot. Reject non-finite lease TTLs.
Add a real two-session regression with an uncommitted holder and a bounded assertion that the second claim returns promptly.
Shipped in v0.3.0-rc.2 (merged to main via #395 at f4c7457): https://github.com/NikolayS/PgQue/releases/tag/v0.3.0-rc.2