Skip to content

fix(subscriptions): keep a failed repeated claim from giving up a lock the owner still holds - #60

Merged
yordis merged 2 commits into
yordis/fix-claim-lock-waitfrom
yordis/fix-repeated-claim-unlock
Oct 26, 2026
Merged

yordis merged 2 commits into
yordis/fix-claim-lock-waitfrom
yordis/fix-repeated-claim-unlock

Conversation

@yordis

@yordis yordis commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

@cursor

cursor Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes ordering and SQL for subscription fencing locks used by event consumers; behavior is heavily tested but touches concurrency-sensitive lock ownership.

Overview
Fixes a bug where a failed repeated subscription lock claim could leave the subscription unlocked even though the original owner still considered itself the holder.

claim_subscription_lock no longer runs advisory locking and lock_generation bumps in one SQL statement. It now runs inside the existing bounded-wait transaction as bump_lock_generation (new UPDATE … RETURNING) followed by try_acquire_exclusive_session_lock, so contention and timeouts happen before trying to take the advisory lock and failed attempts do not need to unlock a lock the current owner already held.

Removes claim_subscription_lock.sql.eex and adds tests for re-claims that fail while waiting on a table lock or after query cancel, asserting the advisory lock stays taken.

Reviewed by Cursor Bugbot for commit 843dcd8. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 296eb950-3f78-47d2-b96f-da9e05708ca8
Commits

Reviewing files that changed from the base of the PR and between c114db1 and 1e0c787.

Files selected for processing: 6
  • lib/event_store/sql/statements.ex
  • lib/event_store/sql/statements/bump_lock_generation.sql.eex
  • lib/event_store/sql/statements/claim_subscription_lock.sql.eex
  • lib/event_store/storage/lock.ex
  • test/advisory_locks_test.exs
  • test/storage/subscription_lock_test.exs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@yordis
yordis added this pull request to stack #73 October 26, 2026 16:00
@yordis yordis changed the title yordis/fix repeated claim unlock fix(subscriptions): keep a failed repeated claim from giving up a lock the owner still holds Oct 26, 2026
@yordis
yordis force-pushed the yordis/fix-repeated-claim-unlock branch from 843dcd8 to 14d51c0 Compare October 26, 2026 16:16
@yordis
yordis removed this pull request from stack #73 October 26, 2026 16:53
@yordis
yordis force-pushed the yordis/fix-repeated-claim-unlock branch from 14d51c0 to 493481a Compare October 26, 2026 16:54
@yordis
yordis added this pull request to stack #74 October 26, 2026 17:10
@yordis
yordis force-pushed the yordis/fix-repeated-claim-unlock branch from 493481a to 44aacf1 Compare October 26, 2026 17:46
… owner still holds

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…k the owner still holds

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis force-pushed the yordis/fix-repeated-claim-unlock branch from 44aacf1 to 1e0c787 Compare October 26, 2026 17:47
@yordis
yordis merged commit 46533ec into main Oct 26, 2026
7 checks passed
@yordis
yordis deleted the yordis/fix-repeated-claim-unlock branch October 26, 2026 19:31
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