rtomayko / rack-cache

Real HTTP Caching for Ruby Web Apps
http://rtomayko.github.io/rack-cache/
Other
822 stars 126 forks source link

RuntimeError: can't add a new key into hash during iteration #169

Closed calebhearth closed 4 years ago

calebhearth commented 4 years ago

I'm seeing this error for an app that I just added rack-cache to. I'm on version 1.12.0 and Ruby version 2.7.1.

The code in question is:

58     def call!(env)
59       @trace = []
60       @default_options.each { |k,v| env[k] ||= v }
61       @env = env
62       @request = Request.new(@env.dup.freeze)

I'm not certain that this issue is coming from Rack::Cache specifically, but I have seen it come up 6 times today in my production app. Is there some way that env and @default_options could be the same hash somehow? It comes up intermittently - refreshing the page once or twice seems to clear this error out.

RuntimeError: can't add a new key into hash during iteration
 [GEM_ROOT]/gems/rack-cache-1.12.0/lib/rack/cache/context.rb:60 :in `block in call!`
 [GEM_ROOT]/gems/rack-cache-1.12.0/lib/rack/cache/context.rb:60 :in `each`
 [GEM_ROOT]/gems/rack-cache-1.12.0/lib/rack/cache/context.rb:60 :in `call!`
 [GEM_ROOT]/gems/rack-cache-1.12.0/lib/rack/cache/context.rb:52 :in `call`
 [GEM_ROOT]/gems/newrelic_rpm-6.12.0.367/lib/new_relic/agent/instrumentation/middleware_tracing.rb:101 :in `call`
 [GEM_ROOT]/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/static.rb:126 :in `call`
 [GEM_ROOT]/gems/newrelic_rpm-6.12.0.367/lib/new_relic/agent/instrumentation/middleware_tracing.rb:101 :in `call`
 [GEM_ROOT]/gems/rack-2.2.3/lib/rack/sendfile.rb:110 :in `call`
 [GEM_ROOT]/gems/newrelic_rpm-6.12.0.367/lib/new_relic/agent/instrumentation/middleware_tracing.rb:101 :in `call`
 [GEM_ROOT]/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/host_authorization.rb:76 :in `call`
 [GEM_ROOT]/gems/newrelic_rpm-6.12.0.367/lib/new_relic/agent/instrumentation/middleware_tracing.rb:101 :in `call`
 [GEM_ROOT]/gems/newrelic_rpm-6.12.0.367/lib/new_relic/agent/instrumentation/middleware_tracing.rb:101 :in `call`
 [GEM_ROOT]/gems/newrelic_rpm-6.12.0.367/lib/new_relic/agent/instrumentation/middleware_tracing.rb:101 :in `call`
 [GEM_ROOT]/gems/newrelic_rpm-6.12.0.367/lib/new_relic/agent/instrumentation/middleware_tracing.rb:101 :in `call`
 [GEM_ROOT]/gems/rack-mini-profiler-2.0.4/lib/mini_profiler/profiler.rb:200 :in `call`
 [GEM_ROOT]/gems/newrelic_rpm-6.12.0.367/lib/new_relic/agent/instrumentation/middleware_tracing.rb:101 :in `call`
 [GEM_ROOT]/gems/scout_apm-2.6.9/lib/scout_apm/instruments/middleware_summary.rb:58 :in `call`
 [GEM_ROOT]/gems/railties-6.0.3.2/lib/rails/engine.rb:527 :in `call`
 [GEM_ROOT]/gems/newrelic_rpm-6.12.0.367/lib/new_relic/agent/instrumentation/middleware_tracing.rb:101 :in `call`
 [GEM_ROOT]/gems/rack-canonical-host-1.0.0/lib/rack/canonical_host.rb:19 :in `call`
 [GEM_ROOT]/gems/newrelic_rpm-6.12.0.367/lib/new_relic/agent/instrumentation/middleware_tracing.rb:101 :in `call`
[GEM_ROOT]/gems/puma-4.3.5/lib/puma/configuration.rb:228 :in `call`
[GEM_ROOT]/gems/puma-4.3.5/lib/puma/server.rb:713 :in `handle_request`
[GEM_ROOT]/gems/puma-4.3.5/lib/puma/server.rb:472 :in `process_client`
[GEM_ROOT]/gems/puma-4.3.5/lib/puma/server.rb:328 :in `block in run`
[GEM_ROOT]/gems/puma-4.3.5/lib/puma/thread_pool.rb:134 :in `block in spawn_thread`
grosser commented 4 years ago

idk how they could be the same, default options are created when initializing the middleware

calebhearth commented 4 years ago

Yeah, fair enough. I’ll check elsewhere in this backtrace. Thanks!