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

Jruby 9.0.0.0: ActionView::Template::Error (can't add a new key into hash during iteration) #3289

Closed
applecrusher opened this issue Aug 26, 2015 · 4 comments

Comments

@applecrusher
Copy link

I have the following code in config/application.rb that I believe is causing the error below.

config.ihp = nil

 config.after_initialize do
      config.ihp = IPHistoryProcessor.new("/home/ubuntu/jruby/logs/inputFiles/" , 1)
 end

I am getting this error on certain pages, I have no idea what could be causing it or how to avoid this.

ActionView::Template::Error (can't add a new key into hash during iteration):
25:     /[if lt IE 9]
26:     = javascript_include_tag 'ie', 'data-turbolinks-track' => true
27:     = javascript_include_tag 'head', 'data-turbolinks-track' => true
28:     = headjs_include_tag 'application', 'data-turbolinks-track' => true
29:     = csrf_meta_tags
30:     = yield :head
31:     = render 'layouts/airbrake'
app/views/layouts/application.html.haml:28:in    
`_app_views_layouts_application_html_haml___1500562678_13328'
app/controllers/dashboard_directors_controller.rb:8:in `get_sales_goals_and_reports_dashboard'
@applecrusher applecrusher changed the title Jruby 9.0.0.0 Jruby 9.0.0.0: ActionView::Template::Error (can't add a new key into hash during iteration) Aug 26, 2015
@headius
Copy link
Member

headius commented Aug 26, 2015

Is there some way to get a more detailed trace that shows the original exception? Modification of a Hash during iteration is officially undefined behavior (in both CRuby and JRuby), so if some code is doing that we should find it and fix it.

@thedarkone
Copy link
Contributor

@applecrusher yes, the error should happen on MRI as well:

> ruby -e'h={:a=>:b}; h.each{ h[:b] = :c }' -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin12.0]
-e:1:in `block in <main>': can't add a new key into hash during iteration (RuntimeError)
    from -e:1:in `each'
    from -e:1:in `<main>'

@applecrusher
Copy link
Author

Sorry for the late reply, I was using Puma for multithreading and I think my app was not multithread safe. Once I disabled multithreading I had no further problems.

@headius
Copy link
Member

headius commented Sep 3, 2015

@applecrusher Ok. Hopefully you can find what hash was being mutated across threads and isolated it. A simple freeze would tell you who is doing the mutation. An alternative would be to dup it before iterating. If it's somewhere in Rails itself, we DEFINITELY want to find the problem, so it doesn't affect other users. I'm happy to help...find me on Twitter or Freenode IRC as headius.

@headius headius added this to the Invalid or Duplicate milestone Sep 3, 2015
@headius headius closed this as completed Sep 3, 2015
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

3 participants