Skip to content

fix(subscriptions): tell lock owners their session is gone without waiting for a stalled lock query to give up - #62

Merged
yordis merged 2 commits into
yordis/fix-owner-down-unlock-retryfrom
yordis/fix-lock-loss-notice-when-busy
Oct 26, 2026
Merged

yordis merged 2 commits into
yordis/fix-owner-down-unlock-retryfrom
yordis/fix-lock-loss-notice-when-busy

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 cluster subscription fencing timing when the lock DB connection stalls; incorrect ordering could briefly mis-notify lock owners, though new tests target the failure mode.

Overview
Fixes delayed lock_released notifications when the advisory-lock DB connection dies while a lock query is still in flight. Previously, the :session_lost notice could sit behind GenServer calls that were blocked on that same connection, so owners kept believing they held locks until every queued request timed out.

AdvisoryLocks now drains a pending :session_lost via handle_pending_session_loss at the start of release, lock attempts, and owner DOWN handling, so session teardown runs before serving later messages. AdvisoryLocks.Protocol notifies the lock server as soon as disconnect starts, caps Postgrex cancel wait at 1s, and turns disconnect_and_retry into a plain disconnect on query paths so a reconnect retry cannot defer handling session loss.

guides/Cluster.md adds a subsection on how quickly nodes detect a dead lock session (active query vs idle ping, timeout, ping_timeout, and server-side TCP settings). Tests add proxied “freeze” scenarios asserting lock_released arrives without waiting for full connection close and before replies to calls queued behind the stalled query.

Reviewed by Cursor Bugbot for commit 79f0a3c. 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 59 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: c171eda4-a471-4a28-8084-0a7da137851e
Commits

Reviewing files that changed from the base of the PR and between e24ad0f and c4e92b8.

Files selected for processing: 4
  • guides/Cluster.md
  • lib/event_store/advisory_locks.ex
  • lib/event_store/advisory_locks/protocol.ex
  • test/advisory_locks_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 lock loss notice when busy fix(subscriptions): tell lock owners their session is gone without waiting for a stalled lock query to give up Oct 26, 2026
@yordis
yordis force-pushed the yordis/fix-lock-loss-notice-when-busy branch from 79f0a3c to 6d0f5aa 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-lock-loss-notice-when-busy branch from 6d0f5aa to f4a59c8 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-lock-loss-notice-when-busy branch 2 times, most recently from cc6b11d to d805e64 Compare October 26, 2026 17:47
…er a stalled query gives up

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…iting for a stalled lock query to give up

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis force-pushed the yordis/fix-lock-loss-notice-when-busy branch from d805e64 to c4e92b8 Compare October 26, 2026 19:31
@yordis
yordis merged commit 446245b into main Oct 26, 2026
7 checks passed
@yordis
yordis deleted the yordis/fix-lock-loss-notice-when-busy branch October 26, 2026 22:05
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