Skip to content

Instantly share code, notes, and snippets.

@pts-owentran
pts-owentran / active_record.rb
Created July 13, 2017 07:13
You can throw this into lib/core_ext in your rails app to prevent implicit connections being made with a stack trace to track down the errant code.
######################
#
# This is hacked from the original code for Rails 4.1. Owen went in and hacked the ConnectionPool
# so it's not fool proof but prevents ShopHotelsCommand from grabbing dozens of idle DB connections.
#
# If you create a thread yourself, if it uses ActiveRecord objects without
# explicitly checking out a connection, one will still be checked out implicitly.
# If it is never checked back in with `ActiveRecord::Base.clear_active_connections!`,
# then it will be leaked.
#