spring
spring copied to clipboard
Running Spring as a background process
Problem:
When we tried to start spring as background process on CircleCI we got this error:
/home/ubuntu/fundbase/vendor/bundle/ruby/1.9.1/bundler/gems/spring-5b27cda52354/lib/spring/sid.rb:41:in `getpgid': No such process (Errno::ESRCH)
from /home/ubuntu/fundbase/vendor/bundle/ruby/1.9.1/bundler/gems/spring-5b27cda52354/lib/spring/sid.rb:41:in `pgid'
from /home/ubuntu/fundbase/vendor/bundle/ruby/1.9.1/bundler/gems/spring-5b27cda52354/lib/spring/server.rb:78:in `set_pgid'
The reason behind this error according to https://github.com/rails/spring/issues/231#issuecomment-31556537 is that CircleCI runs a background process with a command equivalent to nohup bash -c "./daemon &"
and since there is no associated terminal Process.getsid
is returning nil or 0.
Solution:
After some debugging i found that we actually don't need process group ID pgid
on CircleCI and that Session ID sid
is sufficient to keep spring running in background. Thus, i modified self.pgid
method to be:
def self.pgid
return sid if ENV['CIRCLECI']
Process.getpgid(sid)
end
So, I've 2 questions:
1- I'm not sure what can go wrong if we relied on sid
only for background processes?.
2- can we make this configurable ?.
:+1:
+1
Hi! I have same problem on FreeBSD 9.3 (csh) (Rails 4.2.6 Ruby 2.1.7p400)
when I try to
bundle exec spring
It crash and result is:
/home/zYL1WK4y/.bundle/gems/spring-1.6.3/lib/spring/sid.rb:40:in `getpgid': No such process (Errno::ESRCH)
from /home/zYL1WK4y/.bundle/gems/spring-1.6.3/lib/spring/sid.rb:40:in `pgid'
from /home/zYL1WK4y/.bundle/gems/spring-1.6.3/lib/spring/server.rb:78:in `set_pgid'
from /home/zYL1WK4y/.bundle/gems/spring-1.6.3/lib/spring/server.rb:34:in `boot'
from /home/zYL1WK4y/.bundle/gems/spring-1.6.3/lib/spring/server.rb:14:in `boot'
from -e:1:in `<main>'
Problem temporary worked around with code like above showed @AhmedAttyah - thanks for save time! But with no configuration option, becouse have FreeBSD and have no CircleCi:
def self.pgid
return sid
Process.getpgid(sid)
end
Distinctly there is no compatibility in this place.
I have try to debug like this:
def set_pgid
require 'pp';
begin
pp SID
pp SID.pgid
pp Process.setpgid(0, SID.pgid)
rescue Exception => e
puts "exception: #{e.message}"
end
Process.setpgid(0, SID.pgid)
end
The result is:
Spring::SID
exception: No such process
It is wanted to have notification with recomendations instead of crash and make it configurable somehow (or any another way to work)
Does anyone still have such a problem with the new version (check author comment at #504). It would be nice to confirm and to close this one of the issues.