Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError : Can't add a new key into hash during iteration #1781

Closed
pcodeblooded opened this issue Jun 16, 2014 · 3 comments
Closed

RuntimeError : Can't add a new key into hash during iteration #1781

pcodeblooded opened this issue Jun 16, 2014 · 3 comments

Comments

@pcodeblooded
Copy link

Hi,

Very rarely we are getting Runtime Error. Please help us in finding the solution

class HardWorker < BaseWorker

  sidekiq_options :queue => :default, :retry => 0, :backtrace => true, :failures => :exhausted

  def perform(id)
    ActiveRecord::Base.on_shard(:shard_1) do
        10.times do 
          User.find(rand(1..10))
        end
    end
end

#Trace

~/.rvm/gems/ruby-1.9.3-p547@gemset1/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract/connection_pool.rb:296:in `[]='
~/.rvm/gems/ruby-1.9.3-p547@gemset1/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract/connection_pool.rb:296:in `establish_connection'
~/.rvm/gems/ruby-1.9.3-p547@gemset1/gems/active_record_shards-2.7.0/lib/active_record_shards/connection_switcher.rb:182:in `establish_shard_connection'
~/.rvm/gems/ruby-1.9.3-p547@gemset1/gems/active_record_shards-2.7.0/lib/active_record_shards/connection_switcher.rb:153:in `switch_connection'
~/.rvm/gems/ruby-1.9.3-p547@gemset1/gems/active_record_shards-2.7.0/lib/active_record_shards/connection_switcher.rb:15:in `on_shard'
~/project/app/workers/hard_worker.rb:6:in `perform'

We are using the active_record_shards gem for sharding the database.

Can we ignore this error ? Since its coming very rarely.

Thanks

@mperham
Copy link
Collaborator

mperham commented Jun 16, 2014

Sidekiq has never supported rails 2.3. It's likely a thread safety issue in AR's connection pool.

@mperham mperham closed this as completed Jun 16, 2014
@pcodeblooded
Copy link
Author

Thanks for quicker response. Sorry I forgot to mention, we are trying the #1336 because our project is in rails 2.3.

Is there anything we can patch AR's connection pool to make it thread safe? or you suggest us to upgrade to rails 3.

Thanks

@mperham
Copy link
Collaborator

mperham commented Jun 16, 2014

There are reasons Rails 2.3 is not supported; this is one of them. Upgrade or put up with the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants