Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Dead lock on wait in the celluloid actor #3

Closed
k-solutions opened this issue Mar 24, 2013 · 2 comments
Closed

Dead lock on wait in the celluloid actor #3

k-solutions opened this issue Mar 24, 2013 · 2 comments

Comments

@k-solutions
Copy link

Following code fails with:

D, [2013-03-24T17:04:42.494344 #6194] DEBUG -- : Terminating 4 actors...
D, [2013-03-24T17:04:42.495761 #6194] DEBUG -- : Shutdown completed cleanly
/home/hristo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/thread.rb:71:in sleep': deadlock detected (fatal) from /home/hristo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/thread.rb:71:inwait'
from /home/hristo/Public/celluloid/lib/celluloid/mailbox.rb:67:in receive' from /home/hristo/Public/celluloid/lib/celluloid/calls.rb:40:inblock in wait'
from /home/hristo/Public/celluloid/lib/celluloid/calls.rb:39:in loop' from /home/hristo/Public/celluloid/lib/celluloid/calls.rb:39:inwait'
from /home/hristo/Public/celluloid/lib/celluloid.rb:57:in suspend' from /home/hristo/Public/celluloid/lib/celluloid/actor.rb:69:incall'
from /home/hristo/Public/celluloid/lib/celluloid/legacy.rb:14:in method_missing' from examples/redis_pubsub.rb:35:in

'

#!/usr/bin/env ruby

require 'rubygems'
require 'bundler/setup'
require 'celluloid/autostart'
require 'celluloid/redis'

# REDIS = Redis.new( :driver => :celluloid )
class RedisPubSub
  include Celluloid

  def initialize
    @@redis = ::Redis.new( :driver => :celluloid )
  end
  
  def send channel, message
    @@redis.publish channel, message
  end
  
  def run
    wait :terminate
  end
  
  def terminate
    signal :terminate
    super
  end
end

publisher = RedisPubSub.new
at_exit { publisher.terminate }

publisher.send 'test', 'test message'
publisher.run
@tarcieri
Copy link
Member

I'm thinking this deadlock is due to your use of signals. I don't understand what you're trying to accomplish with them.

That said I don't think this is a celluloid-redis or celluloid-related issue at all. If you want to block on the publisher actor, don't use signals, use Celluloid.join(publisher)

@k-solutions
Copy link
Author

Thx for Celluloid.join but subscribe call is still blocking on next address to the actor

#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'celluloid/autostart'
require 'celluloid/redis'
class RedisPubSub
  include Celluloid
  attr_reader :timer
  def initialize
    @redis = ::Redis.new( :driver => :celluloid )
    @timer  = every( 3.5 ) { puts "Hello from timer!" }
  end
  
  def ignate
    @timer.fire
  end
  
  def subscribe *channels #, message
    @redis.subscribe *channels do |on| # , 
      on.message { |channel,msg| puts msg }
    end 
  end
end
publisher = RedisPubSub.new
publisher.async.ignate
publisher.sleep 4
publisher.async.subscribe 'test' # , 'test message'
puts "Subscribed success!"
publisher.async.ignate
publisher.sleep 4
puts "Script ends"

Output from this is

Hello from timer!
Hello from timer!
Subscribed success!

and it stops there

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants