redis / redis-rb

A Ruby client library for Redis
MIT License
3.97k stars 1.03k forks source link

Getting `lib/redis/connection/synchrony.rb:86:in `resume': double resume (FiberError)` #613

Closed robisenberg closed 2 years ago

robisenberg commented 8 years ago

Thanks for the awesome library! I've used it a ton, and it has been incredibly useful.

However, on a new Rails app (4.2.5.2) I'm working on, I'm getting this error (locally and on Heroku) and have spent over a day on this and can't for the life of me figure out what's going wrong! I'm hoping you might be able to help. šŸ˜„

I'm using:

I have an initializer that creates a new connection:

# config/initializers/redis.rb
redis_connection_url = ENV['REDIS_URL'] || "redis://127.0.0.1:6379"
$redis = Redis.new(url: redis_connection_url, driver: :synchrony)

and then some code in my controller that tries to call $redis.get(key) - the failure happens on trying to execute this code.

When I debug the issue, I can see that conn.connected? is false immediately after the following code gets run in lib/redis/connection/synchrony (line 79):

conn = EventMachine.connect(config[:host], config[:port], RedisClient) do |c|
  c.pending_connect_timeout = [config[:connect_timeout], 0.1].max
end

Shouldn't the connection be connected at after this? If so, why would this attempt to connect failed?

Any idea what I'm doing wrong?

Stacktrace

/Users/rob/.gem/ruby/2.3.0/gems/redis-3.3.0/lib/redis/connection/synchrony.rb:86:in `resume': double resume (FiberError)
    from /Users/rob/.gem/ruby/2.3.0/gems/redis-3.3.0/lib/redis/connection/synchrony.rb:86:in `block in connect'
    from /Users/rob/.gem/ruby/2.3.0/gems/eventmachine-1.2.0.1/lib/em/deferrable.rb:158:in `set_deferred_status'
    from /Users/rob/.gem/ruby/2.3.0/gems/eventmachine-1.2.0.1/lib/em/deferrable.rb:198:in `fail'
    from /Users/rob/.gem/ruby/2.3.0/gems/redis-3.3.0/lib/redis/connection/synchrony.rb:65:in `unbind'
    from /Users/rob/.gem/ruby/2.3.0/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:1483:in `event_callback'
    from /Users/rob/.gem/ruby/2.3.0/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:202:in `release_machine'
    from /Users/rob/.gem/ruby/2.3.0/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:202:in `ensure in run'
    from /Users/rob/.gem/ruby/2.3.0/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:205:in `run'
    from /Users/rob/.gem/ruby/2.3.0/gems/thin-1.6.4/lib/thin/backends/base.rb:73:in `start'
    from /Users/rob/.gem/ruby/2.3.0/gems/thin-1.6.4/lib/thin/server.rb:162:in `start'
    from /Users/rob/.gem/ruby/2.3.0/gems/thin-1.6.4/lib/thin/controllers/controller.rb:87:in `start'
    from /Users/rob/.gem/ruby/2.3.0/gems/thin-1.6.4/lib/thin/runner.rb:200:in `run_command'
    from /Users/rob/.gem/ruby/2.3.0/gems/thin-1.6.4/lib/thin/runner.rb:156:in `run!'
    from /Users/rob/.gem/ruby/2.3.0/gems/thin-1.6.4/bin/thin:6:in `<top (required)>'
    from /Users/rob/.gem/ruby/2.3.0/bin/thin:23:in `load'
    from /Users/rob/.gem/ruby/2.3.0/bin/thin:23:in `<main>'

Gemfile

The key bit is:

...
# Redis caching layer
gem 'redis', '~> 3.2', '>= 3.2.2'
gem 'hiredis', '~> 0.6.1'
gem 'em-synchrony'
...

but here's the full thing just in case...

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.2'
# Use postgres as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# renders and parses XML documents from and to Ruby objects
gem 'representable', '~> 3.0.0'
# faraday HTTP Client
gem 'faraday', '~> 0.9.2'
# Improved logging etc for Heroku
gem 'rails_12factor', group: :production

# Redis caching layer
gem 'redis', '~> 3.2', '>= 3.2.2'
gem 'hiredis', '~> 0.6.1'
gem 'em-synchrony'

# Mixin library for Sass
gem 'bourbon', '~> 4.2'

# Use HAML for templating
gem 'haml', '~> 4.0'

# CommonJS support
gem 'browserify-rails', '~> 3.0', '>= 3.0.1'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :test do
  # Stub HTTP Requests
  gem 'webmock', '~> 1.24.0'

  # Defining and using Factories for building test objects
  gem 'factory_girl', '~> 4.5'
end

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # RSpec testing framework
  gem 'rspec-rails', '~> 3.4.2'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :production do
  # higher-performance and needed for EventMachine support
  gem 'thin'
end
byroot commented 2 years ago

synchrony driver was removed in 5.0, so closing as stale.