Skip to content

Commit 482952f

Browse files
ralyodioclaude
andcommitted
fix(queue): lease messages with FOR UPDATE SKIP LOCKED so two readers never share one
Queue.read() selected the visible candidates and then bumped their vt in a second statement. On libSQL the single multiplexed connection and the in-process write lock serialised readers, so that was safe; on the Postgres pool (#239) two concurrent readers see the same candidates and both lease them. The integration test 'never hands the same message to two readers' failed against a real Postgres (36 leases of 10 messages). The select now locks the rows it is about to lease and skips rows another reader holds. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent a346d14 commit 482952f

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎packages/shared/lib/queue.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ export class Queue {
7878
from queue_messages
7979
where queue_name = ? and vt <= ?
8080
order by msg_id
81-
limit ?`,
81+
limit ?
82+
for update skip locked`,
8283
[this.name, nowIso, qty],
8384
);
8485

0 commit comments

Comments
 (0)