4

I am running a modular Sinatra app with ActiveRecord with SQLite on development. I keep on running into ActiveRecord::ConnectionTimeoutError could not obtain a database connection within 5.000 seconds (waited 5.001 seconds) after exceeding my connection pool size.

I have tried all the following methods:

  1. use ActiveRecord::ConnectionAdapater::ConnectionManagement from here
  2. after { ActiveRecord::Base.connection.close } from here
  3. ActiveRecord::Base.clear_active_connections! from here

However, I still keep on getting the same errors!

 # Gemfile
source 'https://rubygems.org'
ruby '2.0.0'

gem 'activerecord', '~> 4.0.2'
gem 'sass', '~> 3.2.12'
gem 'sinatra', '~> 1.4.4'
gem 'sinatra-activerecord'
gem 'sinatra-assetpack', '~> 0.3.1'
gem 'sinatra-contrib', '~> 1.4.2'
gem 'slim', '~> 2.0.2'

group :development do
  gem 'tux'
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end

group :test do
  gem 'database_cleaner'
  gem 'factory_girl', '~> 4.3.0'
  gem 'rspec'
end

# environments.rb
config :development do
  ActiveRecord::Base.establish_connection(
    adapter: 'sqlite3',
    database: 'local.db'
  )
end
Community
  • 1
  • 1
jamesfzhang
  • 4,403
  • 8
  • 32
  • 43
  • How does this help? Instead of getting the error after 5 requests, now it'll just occur after 10. Am I missing something obvious? – jamesfzhang Dec 30 '13 at 18:10
  • do you have sqlite3 in your Gemfile, is it required in your project and can you share your database.yml the portion(development) that has connection details to sqlite – bjhaid Dec 30 '13 at 18:18
  • Updated in original post. – jamesfzhang Dec 31 '13 at 15:09
  • you might need to throw pry into several places to find out what exactly is wrong, your environments.rb looks fine to me, but finally, the issue might as well be then RACK_ENV variable to determine what environment ActiveRecord needs to initiate DB connection for(this is a guess though, you might still need to do some debugging with PRY or Ruby Debugger) – bjhaid Dec 31 '13 at 15:54
  • 5
    have you found a solution? – delphaber Jan 27 '14 at 16:54

0 Answers0