Skip to content

fix(postgres): make advisory lock cancel safe#4199

Merged
abonander merged 3 commits intolaunchbadge:mainfrom
joeydewaal:pg/advisory-lock
Mar 26, 2026
Merged

fix(postgres): make advisory lock cancel safe#4199
abonander merged 3 commits intolaunchbadge:mainfrom
joeydewaal:pg/advisory-lock

Conversation

@joeydewaal
Copy link
Contributor

This pr makes the PgAdvisoryLock::acquire cancel safe by wrapping the connection in a PgAdvisoryLock before actually acquiring the lock. If the acquire future is dropped the drop impl will release the lock.

Does your PR solve an issue?

fixes #4198

Is this a breaking change?

Nope

@joeydewaal
Copy link
Contributor Author

joeydewaal commented Mar 24, 2026

Note: I've decided to not update the try_acquire implementation because releasing the lock depends on the result of the query. So that method is still not cancel safe unfortunately.

Copy link
Collaborator

@abonander abonander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I've decided to not update the try_acquire implementation because releasing the lock depends on the result of the query. So that method is still not cancel safe unfortunately.

Can you just update the documentation to explain that? And add a Cancel Safety clause to the regular lock method that explains what it'll do on cancel?

@abonander abonander merged commit b3df1e5 into launchbadge:main Mar 26, 2026
146 checks passed
@abonander
Copy link
Collaborator

Thanks!

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.

PgAdvisoryLock::acquire is not cancel safe (undocumented footgun)

3 participants