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

DatabaseCleaner improperly starts and ends transactions for ActiveRecord #24

Open
ryanong opened this issue Sep 19, 2014 · 2 comments
Open

Comments

@ryanong
Copy link

ryanong commented Sep 19, 2014

If there is more than one connection in the connection pool DatabaseCleaner will only begin the transaction on one of the connections.
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/fixtures.rb#L979

Any ActiveRecord call afterwards will use the next connection in the pool which does not have a transaction.

When DatabaseCleaner closes the transaction, it will only do so on the next active connection. Thus leaving a connection with an active transaction in the connection pool which can deadlock when doing a deletion cleanup or any table modifications.

DatabaseCleaner should start and end transactions the same way ActiveRecord does by collecting all available connections and starting transactions on all of them.

start: https://github.com/rails/rails/blob/06a9e18e646845ded0f0a46a14c1eb6b3a14e55a/activerecord/lib/active_record/fixtures.rb#L949
end: https://github.com/rails/rails/blob/06a9e18e646845ded0f0a46a14c1eb6b3a14e55a/activerecord/lib/active_record/fixtures.rb#L967

@ryanong ryanong changed the title DatabaseCleaner improperly starts and ends transactions DatabaseCleaner improperly starts and ends transactions for ActiveRecord Sep 19, 2014
@lulalala
Copy link

@ryanong the code line numbers are off because master changed. Can you reference line numbers by some commit please?

@ryanong
Copy link
Author

ryanong commented Sep 30, 2014

@lulalala fixed

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

No branches or pull requests

2 participants