spring
spring copied to clipboard
Spring hangs if the project directory gets removed.
In a situation where spring server has started but then the project directory is deleted, spring throws an error:
/Users/greg/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/spring-1.1.0/lib/spring/configuration.rb:37:in `pwd': No such file or directory - getcwd (Errno::ENOENT)
from /Users/greg/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/spring-1.1.0/lib/spring/configuration.rb:37:in `project_root_path'
from /Users/greg/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/spring-1.1.0/lib/spring/configuration.rb:28:in `application_root_path'
from /Users/greg/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/spring-1.1.0/lib/spring/application.rb:241:in `loaded_application_features'
from /Users/greg/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/spring-1.1.0/lib/spring/application.rb:102:in `ensure in preload'
from /Users/greg/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/spring-1.1.0/lib/spring/application.rb:107:in `preload'
from /Users/greg/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/spring-1.1.0/lib/spring/application/boot.rb:15:in `<top (required)>'
from /Users/greg/.rbenv/versions/2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/greg/.rbenv/versions/2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
caused by Dir.pwd from here.
One solution is that spring could shut down upon encountering that error.
This can be replicated for version 1.1.0 by following these steps (app setup):
rails new spring-test -B
cd spring-test
vi Gemfile
# add `gem 'spring'` to the Gemfile and save.
bundle install
bundle exec spring binstub --all
rails g model person
By now spring server should be running. Now if we remove the app directory
cd .. && rm -rf spring-test
and try to re-run the steps from above (the app setup steps), the last command rails g ... will hang.
I should add, that without using bin/spring this issue doesn't happen.
The problem happens even for me with version 1.1.3.
This is happening to me. I just spent the past hour of my life tracking it down to spring being the culprit. I had never heard of spring until I generated a new Rails 4.1.1 app and started seeing it being used. I was creating a video and generating the app. When I made a mistake during the video, I just deleted everything with 'rm -rf example' and re-generated the app. Everything was fine until I tried to generate scaffolding. It went through all the motions like everything worked, except it did not actually create any files. So I tried 2-3 more times, same results. I was using RubyMine at the time, so I got out and repeated everything from the command line. Same results. So I did 'ps -ax | grep spring' and used kill -9 on the 2 PIDs that came up. Then everything worked again. There was no kind of indication that spring was the culprit, no sort of feedback at all. That is not very nice! The only reason I figured out it was spring was because it was the only thing I noticed that was different than anytime I had done this before.
This happens for me when switching between git branches (on Mac OS X). So it's quite common. I'll try to dig into this if there isn't already a PR.
I think this issue is related to https://github.com/rails/rails/issues/19049#issuecomment-76393965. My guess is that this problem is due to how the spring server is dependent on the app name.
It is hard to determine the real issue but it is definitely not rails related. Mine app_name or "socket_name: length is 59 which should work fine with allowed 108 as maximum length in linux env. Anyone with great 'C' debugging skills?)
It hangs exactly on the next line
@server ||= UNIXSocket.open(env.socket_name)
of the file: /gems/spring-1.6.1/lib/spring/client/run.rb
I got this error too while trying to install simple-form.
Taking your advice I ran: $ ps ax | grep spring
I noticed:
9631 pts/1 Sl 0:00 spring server | my-project | started 42 hours ago
I ran: $ spring stop
and then I could install simple-form
Thank you.