rails/rails — Issue #4671: ActiveRecord query plan logging not thread-safe?
Author: jrochkind
Created: 2012-01-25 16:45:39+00:00
State: open

In a Rails 3.2 app, I am manually spawning threads in application code, wrapping all ActiveRecord calls in a `#with_connection` block, which the docs say is a recommended 'contract' with ActiveRecord: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html

However, the auto-explain-logging of slow queries seems not to be thread-safe, it raises, stack trace below. Note that the stack trace does verify that my AR use is inside a `with_connection` block.

#

["/home/rochkind/.rvm/gems/ruby-1.9.2-p290@umlaut3/gems/activerecord-3.2.0/lib/active_record/explain.rb:32:in `logging_query_plan'",
"/home/rochkind/.rvm/gems/ruby-1.9.2-p290@umlaut3/gems/activerecord-3.2.0/lib/active_record/relation.rb:158:in `to_a'",
"/home/rochkind/.rvm/gems/ruby-1.9.2-p290@umlaut3/gems/activerecord-3.2.0/lib/active_record/relation/finder_methods.rb:377:in `find_first'",
"/home/rochkind/.rvm/gems/ruby-1.9.2-p290@umlaut3/gems/activerecord-3.2.0/lib/active_record/relation/finder_methods.rb:122:in `first'",
"/home/rochkind/.rvm/gems/ruby-1.9.2-p290@umlaut3/gems/activerecord-3.2.0/lib/active_record/relation/finder_methods.rb:335:in `find_one'",
"/home/rochkind/.rvm/gems/ruby-1.9.2-p290@umlaut3/gems/activerecord-3.2.0/lib/active_record/relation/finder_methods.rb:311:in `find_with_ids'",
"/home/rochkind/.rvm/gems/ruby-1.9.2-p290@umlaut3/gems/activerecord-3.2.0/lib/active_record/relation/finder_methods.rb:107:in `find'",
"/home/rochkind/umlaut/app/models/service_wave.rb:71:in `block (3 levels) in handle'",
"/home/rochkind/.rvm/gems/ruby-1.9.2-p290@umlaut3/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:118:in `with_connection'",
"/home/rochkind/umlaut/app/models/service_wave.rb:68:in `block (2 levels) in handle'"]