Skip to content

[1.6.7-HEAD] ConcurrencyError in safe code #141

@arturaz

Description

@arturaz

Problem

I'm getting ConcurrencyError in monitor synchronized code (inside ActiveRecord).

Code

      # Check-in a database connection back into the pool, indicating that you
      # no longer need this connection.
      #
      # +conn+: an AbstractAdapter object, which was obtained by earlier by
      # calling +checkout+ on this pool.
      def checkin(conn)
        synchronize do
          conn.run_callbacks :checkin do
            conn.expire
            @queue.signal
          end

          release conn
        end
      end

      private

      # This method is only called from #checkin, which is synchronized by +MonitorMixin+.
      def release(conn)
        thread_id = nil

        if @reserved_connections[current_connection_id] == conn
          thread_id = current_connection_id
        else
          thread_id = @reserved_connections.keys.find { |k| # Error in this line
            @reserved_connections[k] == conn
          }
        end

        @reserved_connections.delete thread_id if thread_id
      end

Error

Server launched with: --1.9 -J-Dname=nebula_server -J-Djruby.jit.max=25000 --server -J-XX:+TieredCompilation -J-XX:-UseLoopPredicate -Xbacktrace.style=raw -X+C -J-XX:MaxPermSize=256m

Server has encountered an error!

[2012-04-22 20:44:50.981|worker-world_2|main|error] Threading::Worker crashed!
ConcurrencyError: Detected invalid hash contents due to unsynchronized modifications with concurrent users
java/lang/Thread.java:1567:in `getStackTrace'
org/jruby/runtime/backtrace/TraceType.java:59:in `getBacktraceData'
org/jruby/runtime/backtrace/TraceType.java:111:in `getBacktraceData'
org/jruby/runtime/backtrace/TraceType.java:25:in `getBacktrace'
org/jruby/RubyException.java:160:in `prepareBacktrace'
org/jruby/exceptions/RaiseException.java:205:in `preRaise'
org/jruby/exceptions/RaiseException.java:195:in `preRaise'
org/jruby/exceptions/RaiseException.java:112:in `<init>'
org/jruby/Ruby.java:3381:in `newRaiseException'
org/jruby/Ruby.java:3206:in `newConcurrencyError'
org/jruby/RubyHash.java:1913:in `concurrentModification'
org/jruby/RubyHash.java:1356:in `keys'
org/jruby/RubyHash$i$0$0$keys.gen:65535:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:133:in `call'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `release'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$gems$activerecord_minus_3_dot_2_dot_3$lib$active_record$connection_adapters$abstract$connection_pool$method__21$RUBY$release:65535:in `call'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$gems$activerecord_minus_3_dot_2_dot_3$lib$active_record$connection_adapters$abstract$connection_pool$method__21$RUBY$release:65535:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:167:in `call'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:282:in `checkin'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$gems$activerecord_minus_3_dot_2_dot_3$lib$active_record$connection_adapters$abstract$connection_pool$block_19$RUBY$checkin:65535:in `call'
org/jruby/runtime/CompiledBlock19.java:121:in `yieldSpecificInternal'
org/jruby/runtime/CompiledBlock19.java:96:in `yieldSpecific'
org/jruby/runtime/Block.java:99:in `yieldSpecific'
/usr/local/rvm/rubies/jruby-head-n16/lib/ruby/1.9/monitor.rb:201:in `__ensure__'
/usr/local/rvm/rubies/jruby-head-n16/lib/ruby/1.9/monitor.rb:200:in `mon_synchronize'
usr$local$rvm$rubies$jruby_minus_head_minus_n16$lib$ruby$$1_dot_9$monitor$method__14$RUBY$mon_synchronize:65535:in `call'
org/jruby/internal/runtime/methods/AliasMethod.java:81:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:142:in `callBlock'
org/jruby/runtime/callsite/CachingCallSite.java:153:in `callIter'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:276:in `checkin'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$gems$activerecord_minus_3_dot_2_dot_3$lib$active_record$connection_adapters$abstract$connection_pool$method__20$RUBY$checkin:65535:in `call'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$gems$activerecord_minus_3_dot_2_dot_3$lib$active_record$connection_adapters$abstract$connection_pool$method__20$RUBY$checkin:65535:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:167:in `call'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:110:in `release_connection'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$gems$activerecord_minus_3_dot_2_dot_3$lib$active_record$connection_adapters$abstract$connection_pool$method__7$RUBY$release_connection:65535:in `call'
org/jruby/internal/runtime/methods/DynamicMethod.java:211:in `call'
org/jruby/internal/runtime/methods/CompiledMethod.java:260:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:167:in `call'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:121:in `__ensure__'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$gems$activerecord_minus_3_dot_2_dot_3$lib$active_record$connection_adapters$abstract$connection_pool$method__8$RUBY$with_connection:65535:in `call'
org/jruby/internal/runtime/methods/AliasMethod.java:81:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:142:in `callBlock'
org/jruby/runtime/callsite/CachingCallSite.java:153:in `callIter'
/home/spacegame/nebula-server/20120422201639/lib/server/monkey_squad.rb:42:in `with_connection'
home$spacegame$nebula_minus_server$$20120422201639$lib$server$monkey_squad$method__9$RUBY$with_connection:65535:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:142:in `callBlock'
org/jruby/runtime/callsite/CachingCallSite.java:153:in `callIter'
/home/spacegame/nebula-server/20120422201639/lib/server/threading/director/task.rb:31:in `run'
home$spacegame$nebula_minus_server$$20120422201639$lib$server$threading$director$task$method__5$RUBY$run:65535:in `call'
home$spacegame$nebula_minus_server$$20120422201639$lib$server$threading$director$task$method__5$RUBY$run:65535:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:167:in `call'
/home/spacegame/nebula-server/20120422201639/lib/server/threading/worker.rb:21:in `work'
home$spacegame$nebula_minus_server$$20120422201639$lib$server$threading$worker$block_1$RUBY$work:65535:in `call'
org/jruby/runtime/CompiledBlock19.java:121:in `yieldSpecificInternal'
org/jruby/runtime/CompiledBlock19.java:96:in `yieldSpecific'
org/jruby/runtime/Block.java:99:in `yieldSpecific'
/home/spacegame/nebula-server/20120422201639/lib/server/logging/logger.rb:57:in `block'
home$spacegame$nebula_minus_server$$20120422201639$lib$server$logging$logger$method__2$RUBY$block:65535:in `call'
org/jruby/internal/runtime/methods/DynamicMethod.java:219:in `call'
org/jruby/RubyClass.java:611:in `finvoke'
org/jruby/RubyBasicObject.java:1710:in `send19'
org/jruby/RubyKernel.java:2108:in `send19'
org/jruby/RubyKernel$s$send19.gen:65535:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:244:in `callBlock'
org/jruby/runtime/callsite/CachingCallSite.java:250:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:114:in `callVarargs'
/home/spacegame/nebula-server/20120422201639/lib/server/logging/thread_router.rb:7:in `method_missing'
home$spacegame$nebula_minus_server$$20120422201639$lib$server$logging$thread_router$method__1$RUBY$method_missing:65535:in `call'
org/jruby/javasupport/util/RuntimeHelpers.java:497:in `call'
org/jruby/internal/runtime/methods/DynamicMethod.java:219:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:403:in `callMethodMissing'
org/jruby/runtime/callsite/CachingCallSite.java:339:in `cacheAndCall'
org/jruby/runtime/callsite/CachingCallSite.java:212:in `callBlock'
org/jruby/runtime/callsite/CachingCallSite.java:221:in `callIter'
/home/spacegame/nebula-server/20120422201639/lib/server/threading/worker.rb:20:in `work'
home$spacegame$nebula_minus_server$$20120422201639$lib$server$threading$worker$block_0$RUBY$work:65535:in `call'
org/jruby/runtime/CompiledBlock19.java:121:in `yieldSpecificInternal'
org/jruby/runtime/CompiledBlock19.java:96:in `yieldSpecific'
org/jruby/runtime/Block.java:99:in `yieldSpecific'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/bundler/gems/celluloid-53b31cb209dd/lib/celluloid/actor.rb:122:in `__ensure__'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$bundler$gems$celluloid_minus_53b31cb209dd$lib$celluloid$actor$method__18$RUBY$exclusive:65535:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:142:in `callBlock'
org/jruby/runtime/callsite/CachingCallSite.java:148:in `call'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/bundler/gems/celluloid-53b31cb209dd/lib/celluloid.rb:270:in `exclusive'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$bundler$gems$celluloid_minus_53b31cb209dd$lib$celluloid$method__41$RUBY$exclusive:65535:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:142:in `callBlock'
org/jruby/runtime/callsite/CachingCallSite.java:153:in `callIter'
/home/spacegame/nebula-server/20120422201639/lib/server/threading/worker.rb:19:in `work'
home$spacegame$nebula_minus_server$$20120422201639$lib$server$threading$worker$method__3$RUBY$work:65535:in `call'
org/jruby/RubyClass.java:592:in `finvoke'
org/jruby/RubyBasicObject.java:1704:in `send19'
org/jruby/RubyKernel.java:2104:in `send19'
org/jruby/RubyKernel$s$send19.gen:65535:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:342:in `cacheAndCall'
org/jruby/runtime/callsite/CachingCallSite.java:212:in `callBlock'
org/jruby/runtime/callsite/CachingCallSite.java:216:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:113:in `callVarargs'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/bundler/gems/celluloid-53b31cb209dd/lib/celluloid/calls.rb:98:in `dispatch'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$bundler$gems$celluloid_minus_53b31cb209dd$lib$celluloid$calls$method__16$RUBY$dispatch:65535:in `call'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$bundler$gems$celluloid_minus_53b31cb209dd$lib$celluloid$calls$method__16$RUBY$dispatch:65535:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:167:in `call'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/bundler/gems/celluloid-53b31cb209dd/lib/celluloid/actor.rb:223:in `handle_message'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$bundler$gems$celluloid_minus_53b31cb209dd$lib$celluloid$actor$block_9$RUBY$handle_message:65535:in `call'
org/jruby/runtime/CompiledBlock19.java:121:in `yieldSpecificInternal'
org/jruby/runtime/CompiledBlock19.java:96:in `yieldSpecific'
org/jruby/runtime/Block.java:99:in `yieldSpecific'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/bundler/gems/celluloid-53b31cb209dd/lib/celluloid/task.rb:45:in `initialize'
/home/spacegame/nebula-server/20120422201639/vendor/bundle/jruby/1.9/bundler/gems/celluloid-53b31cb209dd/lib/celluloid/task.rb:44:in `initialize'
home$spacegame$nebula_minus_server$$20120422201639$vendor$bundle$jruby$$1_dot_9$bundler$gems$celluloid_minus_53b31cb209dd$lib$celluloid$task$block_0$RUBY$initialize:65535:in `call'
org/jruby/runtime/CompiledBlock19.java:163:in `yield'
org/jruby/runtime/CompiledBlock19.java:149:in `yield'
org/jruby/runtime/Block.java:146:in `yieldArray'
org/jruby/ext/fiber/ThreadFiber.java:38:in `run'
java/util/concurrent/ThreadPoolExecutor.java:1110:in `runWorker'
java/util/concurrent/ThreadPoolExecutor.java:603:in `run'
java/lang/Thread.java:722:in `run'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions