ConnectionPool#release not thread_safe #6464

aselder opened this Issue May 23, 2012 · 6 comments


None yet
4 participants

aselder commented May 23, 2012

I'm doing some pretty heavy concurrent use of ActiveRecord, and noticed so weird stack traces popping up in my logs

2012-05-23T16:44:16Z 4468 TID-940 WARN: Detected invalid hash contents due to unsynchronized modifications with concurrent users
2012-05-23T16:44:16Z 4468 TID-940 WARN: org/jruby/ `keys'
/usr/local/rvm/gems/jruby-1.6.7@new_import/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `release'
/usr/local/rvm/gems/jruby-1.6.7@new_import/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:282:in `checkin'
/usr/local/rvm/rubies/jruby-1.6.7/lib/ruby/1.9/monitor.rb:201:in `mon_synchronize'
/usr/local/rvm/rubies/jruby-1.6.7/lib/ruby/1.9/monitor.rb:200:in `mon_synchronize'
/usr/local/rvm/gems/jruby-1.6.7@new_import/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:276:in `checkin'
/usr/local/rvm/gems/jruby-1.6.7@new_import/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:110:in `release_connection'
/usr/local/rvm/gems/jruby-1.6.7@new_import/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:121:in `with_connection'
/data01/fansnap/import/current/lib/common_import/event_full_importer.rb:29:in `load_db_data'

Is the fix as simple as wrapping the contents of the release method in a synchronize block?


tenderlove commented May 23, 2012

It should be that easy. I think it's fixed on master, but please check. Regardless of whether or not this is fixed on master, please send a patch for 3-2-stable. :-)

aselder commented May 23, 2012

Looks like it's fixed on master. I'll have a pull request for 3-2-stable shortly.

I faced this issue in my production application on Jruby 1.7.4 on Rails 3.2

org.jruby.exceptions.RaiseException: (ConcurrencyError) Detected invalid hash contents due to unsynchronized modifications with concurrent users
 at org.jruby.RubyHash.keys(org/jruby/
 at ActiveRecord::ConnectionAdapters::ConnectionPool.release(/opt/jruby-1.7.3/lib/ruby/gems/shared/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:299)
 at MonitorMixin.mon_synchronize(/opt/jruby-1.7.3/lib/ruby/1.9/monitor.rb:211)

aselder commented Jun 10, 2014

You're using 3.2.8 of rails... This was fixed in a later patch release of rails 3.2

Thank you @aselder I will upgrade :)

@tenderlove I am facing this issue again with following stacks:

jRuby version:

Ubuntu 16.04.3 LTS

JAVA version:

openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

Rails version:
Rails (api)

Application Server
Passenger Entreprise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment