title: ActiveRecord::ConnectionTimeoutError with Sinatra
body: <p>I am running a modular Sinatra app with ActiveRecord with SQLite on development. I keep on running into <code>ActiveRecord::ConnectionTimeoutError could not obtain a database connection within 5.000 seconds (waited 5.001 seconds)</code> after exceeding my connection pool size.</p>
  
  <p>I have tried all the following methods:</p>
  
  <ol>
  <li><code>use ActiveRecord::ConnectionAdapater::ConnectionManagement</code> from <a href="http://snippets.aktagon.com/snippets/621-puma-sinatra-activerecord-and-could-not-obtain-a-database-connection-" rel="nofollow noreferrer">here</a></li>
  <li><code>after { ActiveRecord::Base.connection.close }</code> from <a href="https://stackoverflow.com/questions/13675879/activerecordconnectiontimeouterror">here</a></li>
  <li><code>ActiveRecord::Base.clear_active_connections!</code> from <a href="https://stackoverflow.com/questions/12045495/activerecordconnectiontimeouterror-happening-sporadically">here</a></li>
  </ol>
  
  <p>However, I still keep on getting the same errors!</p>
  
  <pre><code> # Gemfile
  source 'https://rubygems.org'
  ruby '2.0.0'
  
  gem 'activerecord', '~&gt; 4.0.2'
  gem 'sass', '~&gt; 3.2.12'
  gem 'sinatra', '~&gt; 1.4.4'
  gem 'sinatra-activerecord'
  gem 'sinatra-assetpack', '~&gt; 0.3.1'
  gem 'sinatra-contrib', '~&gt; 1.4.2'
  gem 'slim', '~&gt; 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', '~&gt; 4.3.0'
    gem 'rspec'
  end
  
  # environments.rb
  config :development do
    ActiveRecord::Base.establish_connection(
      adapter: 'sqlite3',
      database: 'local.db'
    )
  end
  </code></pre>