From 8e7c93392cca58df97ccda9d2eb8394d7ffd74cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A9=20Dupuis?= Date: Tue, 12 Mar 2024 19:08:03 -0700 Subject: [PATCH] Fix a crash when an Executor wrapped fork exit. Fix #51298 forking inside an Execution Wrapper crashes when running the completion callbacks. Rails 7.0 was not Execution wrapping the `runner` command. Rails 7.2 changed the definition of `active_connection?`, the new definition doesn't contain the bug. Therefore forking inside a script intended to be run with the `runner` command on 7.1 crashes. (see #51298) --- .../connection_adapters/abstract/connection_pool.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 13c745f7fdee5..113cb0ab700b0 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -194,7 +194,7 @@ def connection_class # :nodoc: # #connection or #with_connection methods. Connections obtained through # #checkout will not be detected by #active_connection? def active_connection? - @thread_cached_conns[connection_cache_key(current_thread)] + @thread_cached_conns.try(:[], connection_cache_key(current_thread)) end # Signal that the thread is finished with the current connection.