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

deadlock due to apparent interaction with sleep #13

Open
jhoblitt opened this issue Dec 7, 2013 · 3 comments
Open

deadlock due to apparent interaction with sleep #13

jhoblitt opened this issue Dec 7, 2013 · 3 comments

Comments

@jhoblitt
Copy link

jhoblitt commented Dec 7, 2013

As a disclaimer, I've never worked with celluloid/celluloid-io before today but I can't find any mention of sleep being considered unsafe inside of an actor. Everything was going well with my experiments until I started encountering strange deadlocks. I managed to reduced the problem down to this minimal test case which seems to show some sort of odd interaction between sleep/timers running in the same method as a redis method invocation, but only if the redis method is called before the sleep.

#!/usr/bin/env ruby

require 'celluloid/io'
require 'celluloid/redis'
require 'redis/connection/celluloid'

class RedisTest
  include Celluloid::IO

  def initialize
    @redis = ::Redis.new
  end

  def lookup_redis
    puts "redis lookup"
    @redis.lindex 'fooq', 0
    puts "redis returned\n\n"
  end

  def yawn
    puts "going to sleep"
    sleep 1
    puts "wokeup\n\n"
  end

  def yawn_and_lookup_redis
    puts "going to sleep"
    sleep 1
    puts "wokeup"
    puts "redis lookup"
    record = @redis.lindex 'fooq', 0
    puts "redis returned\n\n"
  end

  def lookup_redis_and_yawn
    puts "redis lookup"
    record = @redis.lindex 'fooq', 0
    puts "redis returned"
    puts "going to sleep"
    sleep 1
    puts "wokeup\n\n"
  end

end

rt = RedisTest.new
rt.lookup_redis
rt.yawn
rt.yawn_and_lookup_redis
rt.lookup_redis_and_yawn

The output I get is:

redis lookup
redis returned

going to sleep
wokeup

going to sleep
wokeup
redis lookup
redis returned

redis lookup
redis returned
going to sleep
<hangs>

If I comment out the line require 'redis/connection/celluloid', so that redis uses it's default connection driver, the script exits normally with the expected output.

@tarcieri
Copy link
Member

tarcieri commented Dec 7, 2013

Celluloid provides its own sleep that interacts with its internal timer system.

That said, this is the likely culprit:

celluloid/celluloid-io#56

@jhoblitt
Copy link
Author

jhoblitt commented Dec 7, 2013

Well that's a bummer but a bit of relief. I've been having flash backs of debugging pthreads + signals for the last 4 hours.

@tarcieri
Copy link
Member

tarcieri commented Dec 7, 2013

It's something we'd like to get fixed really soon but requires some changes to the design of the Mailbox API which is why it's still not fixed.

@halorgium we should get this fixed really soon now! 🔜

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