ActiveRecord::ConnectionTimeoutError

后端 未结 4 1764
轮回少年
轮回少年 2020-12-09 21:20

I am getting this error:

\'could not obtain a database connection within 5 seconds (waited 5.001017 seconds). The max pool size is currently 16; consider inc         


        
4条回答
  •  有刺的猬
    2020-12-09 22:01

    As Frederick pointed out you need to return opened ActiveRecord connections to the connection pool.

    If you're using the Thin server, in threaded mode, then you need to add this to your Sinatra app:

    after do
      ActiveRecord::Base.connection.close
    end
    

    ...instead of using the ConnectionManagement suggestion. The reason is that Thin splits the request processing over 2 threads and the thread that is closing the ActiveRecord connection is not the same as the thread that opened it. As ActiveRecord tracks connections by thread ID it gets confused and won't return connections correctly.

提交回复
热议问题