Repository navigation
fix(subscriptions): stop lock queries from waiting forever on a lock pool that went down #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yordis
merged 13 commits into
yordis/fix-advisory-lock-reconnect
from
yordis/fix-advisory-lock-checkout-hang
Oct 24, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6dd86f6
chore(test): show lock queries hang when the lock pool goes down
yordis 3925c24
fix(subscriptions): stop lock queries from waiting forever on a lock …
yordis 1597086
chore(test): show the lock server crashes when the lock pool monitor …
yordis 67692bf
fix(subscriptions): keep the lock server running when the lock pool m…
yordis f1c5d29
refactor(subscriptions): query the lock pool by its own name
yordis a059370
fix(subscriptions): ignore lock notices for a lock the subscription n…
yordis 60e98e1
feat(storage): record which lock owner may write a subscription's pro…
yordis a9d1209
fix(subscriptions): stop a subscription from writing progress once an…
yordis d6de2e2
chore(guides): describe what the subscription lock guarantees once pr…
yordis 087771f
chore(test): show the lock server fails to start when its pool is down
yordis 245ba33
fix(subscriptions): keep the lock server starting when the lock pool …
yordis 50f8951
chore(test): show an explicit release leaks its lock when the session…
yordis 566dabf
fix(subscriptions): drain an explicit release through the session rec…
yordis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
lib/event_store/sql/statements/claim_subscription_lock.sql.eex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| WITH lock AS ( | ||
| SELECT pg_try_advisory_lock( | ||
| '"<%= schema %>".subscriptions'::regclass::oid::int, | ||
| (CASE WHEN $1 > 2147483647 THEN mod($1, 2147483647) ELSE $1 END)::int | ||
| ) AS acquired, pg_backend_pid() AS pid, COALESCE( | ||
| NULLIF(current_setting('eventstore.session_id', true), ''), | ||
| set_config('eventstore.session_id', md5(random()::text || clock_timestamp()::text), false) | ||
| ) AS session_id | ||
| ), lease AS ( | ||
| UPDATE "<%= schema %>".subscriptions | ||
| SET lock_generation = lock_generation + 1 | ||
| WHERE subscription_id = $1 AND (SELECT acquired FROM lock) | ||
| RETURNING lock_generation, last_seen | ||
| ) | ||
| SELECT lock.acquired, lock.pid, lock.session_id, lease.lock_generation, lease.last_seen | ||
| FROM lock LEFT JOIN lease ON true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| UPDATE "<%= schema %>".subscriptions | ||
| SET last_seen = $2 | ||
| WHERE subscription_id = $1; | ||
| WITH progress AS ( | ||
| UPDATE "<%= schema %>".subscriptions | ||
| SET last_seen = GREATEST(last_seen, $2) | ||
| WHERE subscription_id = $1 AND lock_generation = $3 | ||
| RETURNING subscription_id | ||
| ) | ||
| SELECT EXISTS (SELECT 1 FROM progress) AS acknowledged, | ||
| EXISTS (SELECT 1 FROM "<%= schema %>".subscriptions WHERE subscription_id = $1) AS present; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.