Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sidekiq/redis conflict with websocket_rails: eventmachine not initialized: evma_connect_to_server

I am using sidekiq (2.13.1) (see dependencies here), websocket-rails (0.6.2) (see dependencies here) and redis-semaphore (0.2.1) (see dependencies here).

sidekiq has been running in my application for a long time, but after having installed websocket-rails I am no longer able to perform my sidekiq jobs. They all crash with this stack trace:

2013-09-15T13:15:17Z 12682 TID-ouvinq47w INFO: Sidetiq::Clock start
2013-09-15T13:15:19Z 12682 TID-ouvinq47w INFO: Booting Sidekiq 2.13.1 using redis://localhost:6379/0 with options {}
2013-09-15T13:15:19Z 12682 TID-ouvinq47w INFO: Running in ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
2013-09-15T13:15:19Z 12682 TID-ouvinq47w INFO: See LICENSE and the LGPL-3.0 for licensing details.
2013-09-15T13:15:19Z 12682 TID-ouvinq47w INFO: Starting processing, hit Ctrl-C to stop
2013-09-15T13:15:20Z 12682 TID-ouvjitprc EvaluationsJob JID-7a108bea6da948aee5f43a99 INFO: start
2013-09-15T13:15:20Z 12682 TID-ouvjitprc EvaluationsJob JID-7a108bea6da948aee5f43a99 INFO: fail: 0.003 sec
2013-09-15T13:15:20Z 12682 TID-ouvjitprc WARN: {"retry"=>false, "queue"=>"default", "class"=>"EvaluationsJob", "args"=>["518f599683c336fb87000003"], "jid"=>"7a108bea6da948aee5f43a99", "enqueued_at"=>1379250920.38564}
2013-09-15T13:15:20Z 12682 TID-ouvjitprc WARN: eventmachine not initialized: evma_connect_to_server
2013-09-15T13:15:20Z 12682 TID-ouvjitprc WARN: /Users/john/.rvm/gems/ruby-2.0.0-p247/gems/eventmachine-1.0.3/lib/eventmachine.rb:664:in `connect_server'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/eventmachine-1.0.3/lib/eventmachine.rb:664:in `bind_connect'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/eventmachine-1.0.3/lib/eventmachine.rb:640:in `connect'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/connection/synchrony.rb:72:in `connect'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:271:in `establish_connection'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:69:in `connect'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:290:in `ensure_connected'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:177:in `block in process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:256:in `logging'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:176:in `process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:84:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis.rb:870:in `block in getset'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis.rb:36:in `block in synchronize'
/Users/john/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis.rb:36:in `synchronize'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis.rb:869:in `getset'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-semaphore-0.2.1/lib/redis/semaphore.rb:26:in `exists_or_create!'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-semaphore-0.2.1/lib/redis/semaphore.rb:48:in `lock'
/Users/john/my_app/app/jobs/evaluations_job.rb:9:in `perform'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:48:in `block (3 levels) in process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:115:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:115:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-failures-0.2.1/lib/sidekiq/failures/middleware.rb:10:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:117:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidetiq-0.3.6/lib/sidetiq/middleware.rb:13:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:117:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:117:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/server/retry_jobs.rb:62:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:117:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/logging.rb:22:in `with_context'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/server/logging.rb:7:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:117:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:120:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:120:in `invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:47:in `block (2 levels) in process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:102:in `stats'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:46:in `block in process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:83:in `do_defer'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:37:in `process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `public_send'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `dispatch'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.14.1/lib/celluloid/calls.rb:125:in `dispatch'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.14.1/lib/celluloid/actor.rb:326:in `block in handle_message'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.14.1/lib/celluloid/tasks.rb:42:in `block in initialize'

My issue is related to this Github issue, but my version is websocket-rails (0.6.2), which is higher than the websocket-rails (0.2.1) that was supposed to deal with this issue.

The stack trace refers to my sidekiq job here:

## jobs/evaluations_job.rb

class EvaluationsJob
  include Sidekiq::Worker
  sidekiq_options :retry => false

  def perform(user_id)
    s = Redis::Semaphore.new("perform_evaluations_for_#{user_id}".to_sym, redis: NonBlockingRedis.new(connection: "localhost"))

    if s.lock(-1)  # => THIS IS evaluations_job.rb:9 WHERE IT ALL BREAKS...
      ...
    end
  end
end

I am using the standard settings for both sidekiq and websocket-rails, but as I am not quite sure what is the root of this issue I have included this sidetiq config file in my question (I am using a sidetiq initiated job to start all other jobs):

## config/initializers/sidetiq.rb

Sidekiq.configure_server do |config|
  require 'non_blocking_redis'
  Sidetiq::Clock.start!
end
like image 550
JohnSmith1976 Avatar asked Sep 15 '13 14:09

JohnSmith1976


1 Answers

I believe this might be the solution to fix your problem

https://github.com/websocket-rails/websocket-rails/issues/29

$redis = Redis.new(:host => host, :port => port, :driver => :hiredis)
like image 166
mengqing Avatar answered Oct 12 '22 23:10

mengqing