ActiveRecord::Base.verify_active_connections! 已于 2012 年在 rails commit 9d1f1b1ea9e5d637984fda4f276db77ffd1dbdcb 中删除。所以我们不能使用那个方法。
下面的句子是我简短调查的结果。我不是rails activerecord的专家。所以要小心听。 (但希望这有帮助)
comment in connection_pool.rb说
# 1. Simply use ActiveRecord::Base.connection as with Active Record 2.1 and
# earlier (pre-connection-pooling). Eventually, when you're done with
# the connection(s) and wish it to be returned to the pool, you call
# ActiveRecord::Base.clear_active_connections!. This will be the
# default behavior for Active Record when used in conjunction with
# Action Pack's request handling cycle.
所以也许你(和我。我和你有同样的情况)必须将连接返回到池。
如果要将连接返回到 sinatra 中的池为 Action Pack's request handling cycle,请使用 ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::ConnectionAdapters::ConnectionManagement
然后如 rails commit 9d1f1b1ea9e5d637984fda4f276db77ffd1dbdcb 中所述,我们使用 a different way 和 this line 一样,在使用 Basae.connection 时始终遵循操作包生命周期checkout_and_verify。
def connection
# this is correctly done double-checked locking
# (ThreadSafe::Cache's lookups have volatile semantics)
@reserved_connections[current_connection_id] || synchronize do
@reserved_connections[current_connection_id] ||= checkout
end
end