Skip to content

Commit 7d512c5

Browse files
committed
Active Record Connection Pool: Don't try to clear unowned connections
If `conn.owner` is `nil` there's no point trying to clear the lease, and worse, if we're on Ruby 3.3.5+, `WeakKeyMap#[]` will raise an error when trying to use `nil` as a key.
1 parent 862ab91 commit 7d512c5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,9 @@ def acquire_connection(checkout_timeout)
872872
#--
873873
# if owner_thread param is omitted, this must be called in synchronize block
874874
def remove_connection_from_thread_cache(conn, owner_thread = conn.owner)
875-
@leases[owner_thread].clear(conn)
875+
if owner_thread
876+
@leases[owner_thread].clear(conn)
877+
end
876878
end
877879
alias_method :release, :remove_connection_from_thread_cache
878880

0 commit comments

Comments
 (0)