Skip to content
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

Fix locking #586

Merged
merged 2 commits into from
Apr 3, 2020
Merged

Fix locking #586

merged 2 commits into from
Apr 3, 2020

Conversation

Nevon
Copy link
Contributor

@Nevon Nevon commented Apr 2, 2020

await db.select(`select pg_try_advisory_lock(${PG_MIGRATE_LOCK_ID}) as "lockObtained"`)

This does not return just an array with a boolean, but an array containing an object with a lockObtained property. With the existing implementation every caller would think that it acquired the lock and proceed with migrations. Easily reproducible by just programmatically calling the runner multiple times in a Promise.all, and having the migrations add something with a unique constraint (and index name for example):

await Promise.all([runner(...), runner(...),])

This PR also makes sure that the lock is released. When testing this, I found that once the first runner ran, the next ones never managed to acquire the lock on subsequent retries.

Copy link
Contributor

@dolezel dolezel left a comment

Choose a reason for hiding this comment

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

👍 thanks

@dolezel dolezel merged commit ee60ad2 into salsita:master Apr 3, 2020
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.

2 participants