ddollar/foreman — Issue #153: orphaned processes when killing foreman (deadlock?)
Author: agibralter
Created: 2012-02-13 18:07:52+00:00
State: open

I have the following in `Procfile.development`:

```
redis: bundle exec rake dev:redis
resque: bundle exec rake dev:resque
ts: bundle exec rake ts:run_fg
mail: bundle exec mailcatcher -f -v
```

And I have a convenience rake method to run my profile in development `rake dev:bg`:

```
namespace :dev do

desc 'Start foreman to run background processes (e.g. Redis, Resque, etc.).'
task :bg do
unless pid = fork
exec('foreman start -f Procfile.development')
end
Signal.trap('TERM') { Process.kill('TERM', pid) }
Signal.trap('INT') { Process.kill('INT', pid) }
Process.wait(pid)
end
end
```

For some reason, though, when I `^C` to stop the background tasks, I will occasionally get this error and end up with orphaned processes:

```
^C:8:in `lock': deadlock; recursive locking (ThreadError)
from :8:in `synchronize'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/foreman-0.39.0/lib/foreman/engine.rb:147:in `puts'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/foreman-0.39.0/lib/foreman/engine.rb:41:in `block in start'
from :8:in `call'
from :8:in `synchronize'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/foreman-0.39.0/lib/foreman/engine.rb:147:in `puts'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/foreman-0.39.0/lib/foreman/engine.rb:41:in `block in start'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/foreman-0.39.0/lib/foreman/engine.rb:124:in `call'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/foreman-0.39.0/lib/foreman/engine.rb:124:in `wait2'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/foreman-0.39.0/lib/foreman/engine.rb:124:in `watch_for_termination'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/foreman-0.39.0/lib/foreman/engine.rb:46:in `start'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/foreman-0.39.0/lib/foreman/cli.rb:33:in `start'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/thor-0.14.6/lib/thor.rb:263:in `dispatch'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/gems/foreman-0.39.0/bin/foreman:7:in `'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/bin/foreman:19:in `load'
from /Users/aarongibralter/.rvm/gems/ruby-1.9.3-p0@app/bin/foreman:19:in `

'
```

Does anyone know what's going on?