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

agraves opened this Issue Apr 17, 2012 · 5 comments

5 participants


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.


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


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