guard / guard-spork

Guard::Spork automatically manage Spork DRb servers
https://rubygems.org/gems/guard-spork
MIT License
296 stars 58 forks source link

Errno::EADDRINUSE when using :foreman => true #102

Closed cyrusstoller closed 11 years ago

cyrusstoller commented 11 years ago

In my Guardfile I had the following

guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' }, :foreman => true do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch('config/routes.rb')
  watch(%r{^config/environments/.+\.rb$})
  watch(%r{^config/initializers/.+\.rb$})
  watch('Gemfile')
  watch('Gemfile.lock')
  watch('spec/spec_helper.rb')
  watch(%r{^spec/factories/.+\.rb$})
  watch('test/test_helper.rb')
  watch(%r{^spec/support/.+\.rb$})
end

This was working fine, but when I tried to add a new route to my config/routes.rb I got the following error when Spork was reloading

Loading Spork.prefork block...
Rack::File headers parameter replaces cache_control after Rack 1.5.
Address already in use - bind(2) (Errno::EADDRINUSE)
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `initialize'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `open'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `open_server'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:759:in `block in open_server'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:757:in `each'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:757:in `open_server'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1342:in `initialize'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1624:in `new'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1624:in `start_service'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/gems/spork-0.9.2/lib/spork/server.rb:29:in `listen'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/gems/spork-0.9.2/lib/spork/server.rb:20:in `run'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/gems/spork-0.9.2/lib/spork/runner.rb:75:in `run'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/gems/spork-0.9.2/lib/spork/runner.rb:10:in `run'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/gems/spork-0.9.2/bin/spork:10:in `<top (required)>'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/bin/spork:23:in `load'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/bin/spork:23:in `<main>'

I was able to get normal behavior again when I removed the :foreman => true

I ran Guard in debug mode and saw that it was in fact killing the old PID.

RIght now I'm not writing any tests that depend on vars in .env but I might later.

Thanks for this awesome gem.

thibaudgg commented 11 years ago

Mmm maybe that the PID killed is the Foreman process and that doesn't kill the Spork process launched by it. Make sense?

cyrusstoller commented 11 years ago

I tried running spork in debug mode and it looked like the right spork PIDs were getting killed. How would you check the foreman PIDs?

thibaudgg commented 11 years ago

Mmm so maybe Foreman relaunch it automatically, I don't use Foreman often sorry.

To get Foreman pid try: ps aux | awk '/foreman/&&!/awk/{print $2;}

thibaudgg commented 11 years ago

Still an issue?

cyrusstoller commented 11 years ago

Thanks for working on this. The issue has changed a little.

But if I keep :foreman => true I still get the following error message

Rack::File headers parameter replaces cache_control after Rack 1.5.
Address already in use - bind(2) (Errno::EADDRINUSE)
/Users/cyrusstoller/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `initialize'
/Users/cyrusstoller/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `open'
/Users/cyrusstoller/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `open_server'
/Users/cyrusstoller/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:759:in `block in open_server'
/Users/cyrusstoller/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:757:in `each'
/Users/cyrusstoller/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:757:in `open_server'
/Users/cyrusstoller/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1342:in `initialize'
/Users/cyrusstoller/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1624:in `new'
/Users/cyrusstoller/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1624:in `start_service'
/Users/cyrusstoller/.rvm/gems/ruby-1.9.3-p125@hazelnut/gems/spork-0.9.2/lib/spork/server.rb:29:in `listen'
/Users/cyrusstoller/.rvm/gems/ruby-1.9.3-p125@hazelnut/gems/spork-0.9.2/lib/spork/server.rb:20:in `run'
/Users/cyrusstoller/.rvm/gems/ruby-1.9.3-p125@hazelnut/gems/spork-0.9.2/lib/spork/runner.rb:75:in `run'
/Users/cyrusstoller/.rvm/gems/ruby-1.9.3-p125@hazelnut/gems/spork-0.9.2/lib/spork/runner.rb:10:in `run'
/Users/cyrusstoller/.rvm/gems/ruby-1.9.3-p125@hazelnut/gems/spork-0.9.2/bin/spork:10:in `<top (required)>'
/Users/cyrusstoller/.rvm/gems/ruby-1.9.3-p125@hazelnut/bin/spork:23:in `load'
/Users/cyrusstoller/.rvm/gems/ruby-1.9.3-p125@hazelnut/bin/spork:23:in `<main>'
Running tests with args ["--color"]...
Done.

Then the tests proceed anyway, but the environment hasn't been reloaded. I just did a simple test of changing the routes file to include a unreasonable route and my tests still passed.

thibaudgg commented 11 years ago

Ok, too bad. I'm sorry but I don't use Spork anymore so I'm not sure how to fix that. Maybe we should remove the foreman feature.

cyrusstoller commented 11 years ago

What are you using instead of Spork?

thibaudgg commented 11 years ago

I mostly test my code in isolation without loading Rails. More info at: http://silkandspinach.net/2011/08/08/why-i-dont-use-spork/

cyrusstoller commented 11 years ago

Interesting. I'm always interested in learning how other people test. Most of my service classes I test in isolation. I guess the main reason I load the rails env is for integration tests and testing controllers.

thibaudgg commented 11 years ago

I personally don't test controllers that much, I mostly load rails env for persistence (model) test & integration. So having to wait some seconds for them isn't worth the setup/maintenance of Spork or Zeus.