Skip to content

Conversation

eileencodes
Copy link
Member

In bensheldon/good_job#1103 it was reported that a connection not established is being seen when there are multiple configs for an environment (a multi-db app).

While I think that something is happening where Good Job is accessing the connection while we're checking for pending migrations, this could happen in other gems if we're clobbering the connection on ActiveRecord::Base that is needed.

Here we are making a special class to establish connections to the database. Because the class does not inherit from Base and establishes it's own connection, it won't clobber any existing connections on Base, leaving them in-tact while the app boots.

The reason this wasn't seen in 7.0 is because pending migrations didn't check all the available configs. Once that was fixed this error appeared.

I didn't add a test for this because it's really hard to reproduce without good job and actually booting a server and running a request.

Fixes: #49689

In bensheldon/good_job#1103 it was reported that a connection not
established is being seen when there are multiple configs for an
environment (a multi-db app).

While I think that something is happening where Good Job is accessing
the connection while we're checking for pending migrations, this could
happen in other gems if we're clobbering the connection on
`ActiveRecord::Base` that is needed.

Here we are making a special class to establish connections to the
database. Because the class does not inherit from `Base` and establishes
it's own connection, it won't clobber any existing connections on
`Base`, leaving them in-tact while the app boots.

The reason this wasn't seen in 7.0 is because pending migrations didn't
check all the available configs. Once that was fixed this error
appeared.

I didn't add a test for this because it's really hard to reproduce
without good job and actually booting a server and running a request.

Fixes: rails#49689
@eileencodes eileencodes merged commit f915f41 into rails:main Oct 19, 2023
eileencodes added a commit that referenced this pull request Oct 19, 2023
…ng-migrations-connection

Use custom class for pending migrations connection
@eileencodes eileencodes deleted the use-custom-class-for-pending-migrations-connection branch October 19, 2023 17:17
@eileencodes
Copy link
Member Author

Backported to 7-1-stable in ba2f497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deadlock in check_pending_migrations with multiple databases and missing connects_to
1 participant