Search code examples
ruby-on-railsrubyunicorn

'listen loop error: Socket operation on non-socket' when trying to run Unicorn


I started working on somebody else's Rails project last week. Everything was working as expected throughout the week's work until a couple days ago when I tried to run the server locally (as I had already done many times).

The project uses a rake task to start up the server, but I narrowed the issue down to just trying to get Unicorn running. This is the error I get after running bundle exec unicorn:

I, [2015-04-25T20:38:10.794243 #1249]  INFO -- : listening on addr=0.0.0.0:8080 fd=9
I, [2015-04-25T20:38:10.794400 #1249]  INFO -- : worker=0 spawning...
I, [2015-04-25T20:38:10.795363 #1249]  INFO -- : master process ready
I, [2015-04-25T20:38:10.796474 #1250]  INFO -- : worker=0 spawned pid=1250
I, [2015-04-25T20:38:10.797102 #1250]  INFO -- : Refreshing Gem list
I, [2015-04-25T20:38:17.102292 #1250]  INFO -- : worker=0 ready
E, [2015-04-25T20:38:17.102705 #1250] ERROR -- : listen loop error: Socket operation on non-socket - accept (Errno::ENOTSOCK)
E, [2015-04-25T20:38:17.102861 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:669:in `kgio_tryaccept'
E, [2015-04-25T20:38:17.103015 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:669:in `worker_loop'
E, [2015-04-25T20:38:17.103201 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525:in `spawn_missing_workers'
E, [2015-04-25T20:38:17.103345 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:140:in `start'
E, [2015-04-25T20:38:17.103473 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
E, [2015-04-25T20:38:17.103658 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/bin/unicorn:23:in `load'
E, [2015-04-25T20:38:17.103780 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/bin/unicorn:23:in `<main>'
E, [2015-04-25T20:38:17.103901 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/bin/ruby_executable_hooks:15:in `eval'
E, [2015-04-25T20:38:17.104022 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/bin/ruby_executable_hooks:15:in `<main>'
E, [2015-04-25T20:38:17.104289 #1250] ERROR -- : listen loop error: Socket operation on non-socket - accept (Errno::ENOTSOCK)
E, [2015-04-25T20:38:17.104379 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:669:in `kgio_tryaccept'
E, [2015-04-25T20:38:17.104533 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:669:in `worker_loop'
E, [2015-04-25T20:38:17.104711 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525:in `spawn_missing_workers'
E, [2015-04-25T20:38:17.104844 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:140:in `start'
E, [2015-04-25T20:38:17.104977 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
E, [2015-04-25T20:38:17.105107 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/bin/unicorn:23:in `load'
E, [2015-04-25T20:38:17.105235 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/bin/unicorn:23:in `<main>'
E, [2015-04-25T20:38:17.105333 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/bin/ruby_executable_hooks:15:in `eval'
E, [2015-04-25T20:38:17.105465 #1250] ERROR -- : /Users/me/.rvm/gems/ruby-2.2.0@project_name/bin/ruby_executable_hooks:15:in `<main>'
E, [2015-04-25T20:38:17.105794 #1250] ERROR -- : listen loop error: Socket operation on non-socket - accept (Errno::ENOTSOCK)

There are multiple projects on this machine, but I don't think any were even worked on in between the working state and broken state.

I did run an OSX update that had been harassing me for a week the morning before this all broke. Unicorn also updated on the day the project started failing on me. But I've tried reverting XCode to an older version, and I tried locking the Unicorn gem to the 'working' version, and none of it seems to make the difference.

I've also tried specifying a different port in case that is the issue: bundle exec unicorn -p 4444, but to no avail.

Any help is appreciated.


Solution

  • Might want to rebuild this application's gemset. If anything, you'll recompile your native gems. Perhaps there's some merit, given the error is occurring pretty deep within Unicorn.

    Check out: RVM Gemset for info on deleting

    After that, go ahead and bundle install. Hopefully that resolves the issue.