celluloid/celluloid — pull request #362 by jnicklas (2013-12-10 12:38:45+00:00)
Title: Celluloid.shutdown does not shut down cleanly when TaskThread is used

If the Actor has a finalizer and `task_class TaskThread` is used, shutting down Celluloid does not complete cleanly, and the finalizer is not run. Here's a minimal repro:

``` ruby
require "celluloid"
require "logger"

$CELLULOID_DEBUG = true
Celluloid.logger = Logger.new($stdout)

class Mediator
include Celluloid

task_class TaskThread

finalizer :monkey

def monkey
# No op.
end
end

actor = Mediator.new

sleep 1
Celluloid.shutdown
```

This fails on JRuby, MRI and rbx, consistently. Output:

```
~/Projects/celluloid$ ruby -Ilib test.rb
D, [2013-12-10T13:35:34.433723 #35371] DEBUG -- : Terminating 1 actor...
E, [2013-12-10T13:35:44.434688 #35371] ERROR -- : Couldn't cleanly terminate all actors in 10 seconds!
```

In the attached pull request, we've moved the shutdown of the internal pool after the shutdown of the actors. This seems to fix the issue for us, but we're not sure if this has other undesired side-effects. Also, we couldn't run the test suite on JRuby and rbx because we were getting deadlocks (even without our changes).

The test we added consistently fails on all rubies before our change, and consistently passes after.