Repository navigation
Closed
Description
How to reproduce:
Run multiple times the following query in psql while the server is running to simulate a database restart or crash:
SELECT pg_terminate_backend(pid) FROM pg_stat_activity;In the error logs you will see something like this:
15:58:26 web.1 | SolidCable::Message Load (24.3ms) SELECT "solid_cable_messages".* FROM "solid_cable_messages" WHERE "solid_cable_messages"."channel_hash" IN (2107490384321251451, -5756308531068617540) AND "solid_cable_messages"."id" >= 18108 ORDER BY "solid_cable_messages"."id" ASC /*application='MitigateChatBot'*/
15:58:26 web.1 | SolidCable::Message Load (14.1ms) SELECT "solid_cable_messages".* FROM "solid_cable_messages" WHERE "solid_cable_messages"."channel_hash" IN (2107490384321251451, -5756308531068617540) AND "solid_cable_messages"."id" >= 18108 ORDER BY "solid_cable_messages"."id" ASC /*application='MitigateChatBot'*/
15:58:26 web.1 | #<Thread:0x00000001535cb058@solid_cable_listener /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/solid_cable-3.0.12/lib/action_cable/subscription_adapter/solid_cable.rb:54 run> terminated with exception (report_on_exception is true):
15:58:26 web.1 | /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:167:in 'PG::Connection#exec': PQconsumeInput() FATAL: terminating connection due to administrator command (ActiveRecord::ConnectionFailed)
15:58:26 web.1 | server closed the connection unexpectedly
15:58:26 web.1 | This probably means the server terminated abnormally
15:58:26 web.1 | before or while processing the request.
15:58:26 web.1 |
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:167:in 'ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements#perform_query'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:571:in 'block (2 levels) in ActiveRecord::ConnectionAdapters::DatabaseStatements#raw_execute'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:1081:in 'block in ActiveRecord::ConnectionAdapters::AbstractAdapter#with_raw_connection'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/rubies/ruby-3.4.5/lib/ruby/gems/3.4.0/gems/activesupport-8.1.1/lib/active_support/concurrency/null_lock.rb:9:in 'ActiveSupport::Concurrency::NullLock#synchronize'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:1050:in 'ActiveRecord::ConnectionAdapters::AbstractAdapter#with_raw_connection'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:570:in 'block in ActiveRecord::ConnectionAdapters::DatabaseStatements#raw_execute'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/rubies/ruby-3.4.5/lib/ruby/gems/3.4.0/gems/activesupport-8.1.1/lib/active_support/notifications/instrumenter.rb:58:in 'ActiveSupport::Notifications::Instrumenter#instrument'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/sentry-rails-6.1.2/lib/sentry/rails/tracing.rb:56:in 'Sentry::Rails::Tracing::SentryNotificationExtension#instrument'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:1201:in 'ActiveRecord::ConnectionAdapters::AbstractAdapter#log'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:569:in 'ActiveRecord::ConnectionAdapters::DatabaseStatements#raw_execute'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:613:in 'ActiveRecord::ConnectionAdapters::DatabaseStatements#internal_execute'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:555:in 'ActiveRecord::ConnectionAdapters::DatabaseStatements#internal_exec_query'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:708:in 'ActiveRecord::ConnectionAdapters::DatabaseStatements#select'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:76:in 'ActiveRecord::ConnectionAdapters::DatabaseStatements#select_all'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:275:in 'block in ActiveRecord::ConnectionAdapters::QueryCache#select_all'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:313:in 'block (2 levels) in ActiveRecord::ConnectionAdapters::QueryCache#cache_sql'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:90:in 'ActiveRecord::ConnectionAdapters::QueryCache::Store#compute_if_absent'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:311:in 'block in ActiveRecord::ConnectionAdapters::QueryCache#cache_sql'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/rubies/ruby-3.4.5/lib/ruby/gems/3.4.0/gems/activesupport-8.1.1/lib/active_support/concurrency/null_lock.rb:9:in 'ActiveSupport::Concurrency::NullLock#synchronize'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:310:in 'ActiveRecord::ConnectionAdapters::QueryCache#cache_sql'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:275:in 'ActiveRecord::ConnectionAdapters::QueryCache#select_all'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/querying.rb:68:in 'ActiveRecord::Querying#_query_by_sql'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/relation.rb:1473:in 'block (2 levels) in ActiveRecord::Relation#exec_main_query'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:463:in 'ActiveRecord::ConnectionAdapters::ConnectionPool#with_connection'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/connection_handling.rb:313:in 'ActiveRecord::ConnectionHandling#with_connection'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/relation.rb:1472:in 'block in ActiveRecord::Relation#exec_main_query'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/relation.rb:1494:in 'ActiveRecord::Relation#skip_query_cache_if_necessary'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/relation.rb:1456:in 'ActiveRecord::Relation#exec_main_query'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/relation.rb:1434:in 'block in ActiveRecord::Relation#exec_queries'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/relation.rb:1494:in 'ActiveRecord::Relation#skip_query_cache_if_necessary'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/relation.rb:1428:in 'ActiveRecord::Relation#exec_queries'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/relation.rb:1201:in 'ActiveRecord::Relation#load'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/relation.rb:353:in 'ActiveRecord::Relation#records'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/activerecord-8.1.1/lib/active_record/relation/delegation.rb:100:in 'ActiveRecord::Delegation#each'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/solid_cable-3.0.12/lib/action_cable/subscription_adapter/solid_cable.rb:128:in 'ActionCable::SubscriptionAdapter::SolidCable::Listener#broadcast_messages'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/solid_cable-3.0.12/lib/action_cable/subscription_adapter/solid_cable.rb:66:in 'block (2 levels) in ActionCable::SubscriptionAdapter::SolidCable::Listener#listen'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/solid_cable-3.0.12/lib/action_cable/subscription_adapter/solid_cable.rb:146:in 'ActionCable::SubscriptionAdapter::SolidCable::Listener#with_polling_volume'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/solid_cable-3.0.12/lib/action_cable/subscription_adapter/solid_cable.rb:66:in 'block in ActionCable::SubscriptionAdapter::SolidCable::Listener#listen'
15:58:26 web.1 | from <internal:kernel>:168:in 'Kernel#loop'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/solid_cable-3.0.12/lib/action_cable/subscription_adapter/solid_cable.rb:63:in 'ActionCable::SubscriptionAdapter::SolidCable::Listener#listen'
15:58:26 web.1 | from /Users/ebeigarts/.rvm/gems/ruby-3.4.5@mitigate-chat-bot/gems/solid_cable-3.0.12/lib/action_cable/subscription_adapter/solid_cable.rb:58:in 'block in ActionCable::SubscriptionAdapter::SolidCable::Listener#initialize'
After the query raises an error:
- There are no more
SolidCable::Message Load (24.3ms) SELECT "solid_cable_messages".*queries, because the listener thread has crashed - Other requests are working correctly
- Nothing gets broadcasted until the web server is restarted
Redis adapter listens to server errors and has retries:
Postgres adapter does not have any error handling/retries:
Solid queue adapter also does not have error handling/retries:
It would be great to have similar error handling/retries to Redis adapter in Solid Cable adapter to make it more resilient to database connection issues.
Metadata
Metadata
Assignees
Labels
No labels
Activity
npezza93 commentedon Dec 12, 2025
Hey @ebeigarts, thanks for the report. ill check it out and see what we can do to recover here
ebeigarts commentedon Dec 15, 2025
Our current workaround:
I'm not sure if it makes sense to add
reconnect_attemptsas in redis, I think it should try to recover indefinitely. I think this is what most users expect and would be the best DX.Options:
reconnect_attemptsas in redis, but then it would still be broken after max reconnect attempts are reached :(reconnect_attemptsas in redis, but also stop puma after the reconnect_attempts are reachedreconnect_attemptsas in redis, but also add health checks, so that/updisplays an errorInteNs commentedon May 21, 2026
@npezza93 any idea when we can expect a new gem release with this fix?
edit: it seems the workaround doesn't fix it for us as we get a
ActiveRecord::ConnectionNotEstablishedwhen our database restarts, notActiveRecord::ConnectionFailedshould i create a new issue for this?npezza93 commentedon May 21, 2026
@InteNs Ill cut a release this weekend. I also added connection not established and timeout error to the list of retryable errors in beb66b2. Give main a try again