Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Migrations failing due to ConcurrentMigrationError while trying to release an already acquired lock #32622
Steps to reproduce
Migration should run successfully
ConcurrentMigrationError. The logs are follows:
Rails version: 5.2.0
This error happened while upgrading from Rails 5.1 to Rails 5.2. The migrate command ran fine on Rails 5.1 in the same environment. There were no migrations to run in this deployment.
I finally figured that this is not a rails issue. Rails takes an advisory lock to prevent concurrent migrations on the same DB.
After we switched from transaction pooling to session pooling in PGBouncer, the issue went away. The underlying problem can be attributed to the incompatibility between advisory looks and transaction pooling and thus testing it again on Rails 5.1 revealed that the same issue occurred there, only that Rails 5.2 started throwing exception if it failed to release the lock.
This issue has been automatically marked as stale because it has not been commented on for at least three months.