rack-attack: After install: ThreadError: deadlock; recursive locking

Using Rails 3.2, added rack-attack to Gemfile and bundled. Then created an initializer with only the following rule:

Rack::Attack.throttle("req/ip", :limit => 10, :period => 1) { |req| req.ip }

Now when I make any request to my app, I get the following error over and over:

ThreadError: deadlock; recursive locking
ruby-2.0.0-p247@project/gems/rack-1.4.5/lib/rack/lock.rb:14:in `lock'
ruby-2.0.0-p247@project/gems/rack-1.4.5/lib/rack/lock.rb:14:in `call'
ruby-2.0.0-p247@project/gems/actionpack-3.2.15/lib/action_dispatch/middleware/static.rb:63:in `call'
ruby-2.0.0-p247@project/gems/sentry-raven-0.6.0/lib/raven/rack.rb:47:in `call'
ruby-2.0.0-p247@project/gems/rack-rewrite-1.3.3/lib/rack/rewrite.rb:20:in `call'
ruby-2.0.0-p247@project/gems/railties-3.2.15/lib/rails/engine.rb:484:in `call'
ruby-2.0.0-p247@project/gems/railties-3.2.15/lib/rails/application.rb:231:in `call'
ruby-2.0.0-p247@project/gems/railties-3.2.15/lib/rails/railtie/configurable.rb:30:in `method_missing'
ruby-2.0.0-p247@project/gems/rack-1.4.5/lib/rack/deflater.rb:13:in `call'
ruby-2.0.0-p247@project/gems/rack-1.4.5/lib/rack/lint.rb:48:in `_call'
ruby-2.0.0-p247@project/gems/rack-1.4.5/lib/rack/lint.rb:36:in `call'
ruby-2.0.0-p247@project/gems/rack-1.4.5/lib/rack/showexceptions.rb:24:in `call'
ruby-2.0.0-p247@project/gems/rack-1.4.5/lib/rack/commonlogger.rb:33:in `call'
ruby-2.0.0-p247@project/gems/sinatra-1.4.3/lib/sinatra/base.rb:212:in `call'
ruby-2.0.0-p247@project/gems/rack-1.4.5/lib/rack/chunked.rb:43:in `call'
ruby-2.0.0-p247@project/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
ruby-2.0.0-p247@project/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:580:in `process_client'
ruby-2.0.0-p247@project/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:660:in `worker_loop'
ruby-2.0.0-p247@project/gems/newrelic_rpm-3.6.6.147/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `call'
ruby-2.0.0-p247@project/gems/newrelic_rpm-3.6.6.147/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `block (4 levels) in <top (required)>'
ruby-2.0.0-p247@project/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:527:in `spawn_missing_workers'
ruby-2.0.0-p247@project/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:153:in `start'
ruby-2.0.0-p247@project/gems/unicorn-4.7.0/bin/unicorn:126:in `<top (required)>'
ruby-2.0.0-p247@project/bin/unicorn:23:in `load'
ruby-2.0.0-p247@project/bin/unicorn:23:in `<main>'
ruby-2.0.0-p247@project/bin/ruby_noexec_wrapper:14:in `eval'
ruby-2.0.0-p247@project/bin/ruby_noexec_wrapper:14:in `<main>'

I’m using redis 3.0.4 driver as my Rails cache.

Other rack middleware I’m using:

  • rack-mobile-detect
  • rack-p3p
  • rack-rewrite
  • rack-ssl-enforcer

Any ideas what could be wrong?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 26

Commits related to this issue

Most upvoted comments

For anyone that stumbles upon this: This error is likely due to Redis being overwhelmed with requests.

Examples:

  • Rack::Attack uses the Rails cache to store IPs, etc. If you configured the Rails cache to use Redis, then that’s source of the problem.
  • Rails.cache.fetch or <% cache do %> blocks also use the rails cache, which could be using Redis

Either reduce the number of Redis clients (what @ostinelli did), or scale up your Redis to be able to manage more concurrent connections.