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

Avoid new connections to the primary node. #35

Closed
wants to merge 2 commits into from

Conversation

nicholasdower
Copy link

@nicholasdower nicholasdower commented Jul 18, 2021

#36

Standby::Base.inside_transaction? uses ActiveRecord::Base.connection on the primary to check whether access to the standby is occurring from within a transaction. ActiveRecord::Base.connection looks for a cached connection belonging to the current thread and, if it doesn't find one, attempts to checkout a connection from the connection pool. If the connection pool is exhausted, it blocks for up to ConnectionPool#checkout_timeout (default 5 seconds).

This change skips the transaction check if a connection has not been cached for the current thread. The assumption is there cannot be a current transaction without a current connection.

Also rename slavery_spec.rb to match renames done in d0e8c74.

@nicholasdower nicholasdower changed the title Don't create new connections to the primary node. Avoid new connections to the primary node. Jul 18, 2021
@nicholasdower nicholasdower force-pushed the primary branch 2 times, most recently from 51338c7 to ff353f2 Compare July 18, 2021 20:11
`Standby::Base.inside_transaction?` uses `ActiveRecord::Base.connection`
on the primary to check whether access to the standby is occurring from
within a transaction. `ActiveRecord::Base.connection` looks for a cached
connection belonging to the current thread and, if it doesn't find one,
attempts to checkout a connection from the connection pool. If the
connection pool is exhausted, it blocks for up to
`ConnectionPool#checkout_timeout` (default 5 seconds).

This change skips the transaction check if a connection has not been
cached for the current thread. The assumption is there cannot be a
current transaction without a current connection.
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.

None yet

1 participant