Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Rake can't drop database unless Rspec has been run first #188

agraves opened this Issue Apr 17, 2012 · 5 comments


None yet
5 participants

agraves commented Apr 17, 2012

I've been seeing this issue consistently for a while now. Basically, when I start spork, if I run "rake" first, I always get this error message:

rake aborted!
FOO::Error: ERROR:  database "foo_test" is being accessed by other users
DETAIL:  There are 1 other session(s) using the database.

If I run any unit test via rspec directly, it will work, and then rake will work every time until I restart the server.


spork (1.0.0rc2)
spork-rails (3.2.0)

We're also using database-cleaner, if that matters.

fringd commented May 18, 2012

this affects me as well...

+1 here too

This is because rake does a db:test:prepare, which tries to drop the test database, but spork holds on to a connection to the test database after the prefork block completes. I fixed this by adding this line to the bottom of my prefork block:

p "Done setting up. Closing DB connections in test"

I did not have to add any connection code to the each_run block - apparently Rails will re-establish whatever connections it needs.

Sent a pull request to spork-rails that will fix it: sporkrb/spork-rails#9

jure commented Aug 9, 2012

Just removing the connection did not do the trick for me, Rails 3.2.6 did not re-establish it.

I used

Spork.each_run do

And it works perfectly now.

@sarahmei sarahmei referenced this issue in sporkrb/spork-rails Dec 10, 2012


Close ActiveRecord connections at end of prefork #9

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