LoginSignup
7
9

More than 5 years have passed since last update.

Rails:4.2.5 Redis:3.2.2 Errno::ECONNREFUSED Redis::CannotConnectErrorを倒す

Last updated at Posted at 2016-03-15

問題

トリガーするとError connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) (Redis::CannotConnectError)でアプリケーションが落ちてしまう。

/path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:332:in `rescue in establish_connection': Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) (Redis::CannotConnectError)
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:318:in `establish_connection'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:94:in `block in connect'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:280:in `with_reconnect'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:93:in `connect'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:351:in `ensure_connected'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:208:in `block in process'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:293:in `logging'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:207:in `process'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:113:in `call'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:2085:in `block in publish'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:57:in `block in synchronize'
    from /Users/hirokishirai/.rbenv/versions/2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:57:in `synchronize'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:2084:in `publish'
    from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/websocket-rails-0.7.0/lib/websocket_rails/synchronization.rb:63:in `block in publish'

2つの解決策

どちらも動作確認済みです。
moaaさんのfixesをそのまま使っちゃうか、とりあえずredisを3.2.0にダウングレードしてwebsocket-railのマスターにfixesがマージされるのを待つかです。どちらでも良いと思います。

方法1 moaa/websocket-railssync_fixesブランチを使う

Gemfileを次のように書き換える

- gem 'websocket-rails'
+ gem 'websocket-rails', github: 'moaa/websocket-rails', branch: 'sync_fixes'

方法2 gem 'redis'のバージョンを3.2.0にダウングレードする

Gemfileを次のように書き換える

- gem 'redis'
+ gem 'redis', '3.2.0'

redisをupdate(Gemfile.lockでバージョンがロックされているのでbundle installは通らないはず)

bundle update redis

Source↓

Redis error when sending two different messages · Issue #313 · websocket-rails/websocket-rails

7
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
9