ActiveRecord::Base.connected?在数据库宕机后仍返回true的问题咨询
ActiveRecord::Base.connected? Returns True Even When Database Goes Down (After Initial Connection)
I've run into this quirky behavior with Rails' ActiveRecord: once your Rails app establishes an initial connection to the database (DB), calling ActiveRecord::Base.connected? will still return true even if the database later becomes unavailable or crashes.
Here's how you can reproduce this issue step by step:
- Start your Rails application along with its database container (like Docker for PostgreSQL or MySQL)
- Wait until the Rails app is fully up and running, confirming it's successfully connected to the DB
- Stop the database container to simulate a database outage
- Launch a
rails consolesession - Check the return value of
ActiveRecord::Base.connected?— you'll see it still returnstrue
内容的提问来源于stack exchange,提问作者Jimbali
相关产品推荐
相关产品推荐

