spring: Spring hangs a lot
We’ve been having a lot of problems with spring hanging on our systems. I started outputting to a log and here’s what I see:
[2015-03-19 14:27:01 -0700] [21417] [application:test] initialized -> running
/home/fletch/.rvm/gems/ruby-2.1.5/gems/spring-1.3.3/lib/spring/application.rb:286:in `read': stream closed (IOError)
from /home/fletch/.rvm/gems/ruby-2.1.5/gems/spring-1.3.3/lib/spring/application.rb:286:in `block (2 levels) in with_pty'
[2015-03-19 14:27:01 -0700] [12838] [application_manager:test] child 21417 shutdown
[2015-03-19 14:27:01 -0700] [21531] [application:test] preloading app
[2015-03-19 14:27:06 -0700] [21531] [application:test] initialized -> running
/home/fletch/.rvm/gems/ruby-2.1.5/gems/spring-1.3.3/lib/spring/application.rb:286:in `read': stream closed (IOError)
from /home/fletch/.rvm/gems/ruby-2.1.5/gems/spring-1.3.3/lib/spring/application.rb:286:in `block (2 levels) in with_pty'
I haven’t got a strong idea of what is causing it just yet, though it seems to come up if we change git branches and the like, so maybe some sort of file changes are causing it to just lock up. We have to run spring stop
and start over.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 13
- Comments: 59 (7 by maintainers)
Links to this issue
Commits related to this issue
- Configure threads to not abort on exceptions (#484) * Configure all threads to not abort on exceptions This solves long outstanding issue: https://github.com/rails/spring/issues/396. This happens... — committed to rails/spring by ayufan 8 years ago
- Kill PTY I/O thread when we are done with it Sometimes the PTY slave can be closed, causing an unhandled exception in the thread which is calling `master.read` (socket closed). This change kills the... — committed to misterbyrne/spring by misterbyrne 8 years ago
- Kill PTY I/O thread when we are done with it Sometimes the PTY slave can be closed, causing an unhandled exception in the thread which is calling `master.read` (socket closed). This change kills the... — committed to misterbyrne/spring by misterbyrne 8 years ago
- Kill PTY I/O thread when we are done with it Sometimes the PTY slave can be closed, causing an unhandled exception in the thread which is calling `master.read` (socket closed). This change kills the... — committed to misterbyrne/spring by misterbyrne 8 years ago
- Kill PTY I/O thread when we are done with it (#497) Sometimes the PTY slave can be closed, causing an unhandled exception in the thread which is calling `master.read` (socket closed). This change... — committed to rails/spring by misterbyrne 8 years ago
- Configure threads to not abort on exceptions (#484) * Configure all threads to not abort on exceptions This solves long outstanding issue: https://github.com/rails/spring/issues/396. This happens... — committed to smartech7/ruby-preloader-spring by ayufan 8 years ago
- Kill PTY I/O thread when we are done with it (#497) Sometimes the PTY slave can be closed, causing an unhandled exception in the thread which is calling `master.read` (socket closed). This change... — committed to smartech7/ruby-preloader-spring by misterbyrne 8 years ago
Spring 2.0.2, Rails 5.1.4. Happens so much that I have an alias for
spring stop
+1 Spring status says Spring is not running (because I stopped it), but ps shows Spring processes still going.
Seeing spring hang a lot with a new Rails 5.2.1 project on macOS 10.13.5 High Sierra
Only thing I can do is
kill -9
the Ruby process, and thenbin/spring stop
, followed bybin/rails test
Seems to happen most often when files in the
config
directory are modified.Maybe this will help someone: while in the beginning I thought that
spring
is the issue, in my specific case ruby process eating 100% CPU was solved by explicitly updatinglisten
gem version used inspring-watcher-listen
gem that we had in the project.Wow, 7 years later, finally fixed! 🎉
Rails 5.1.5, Spring 2.0.2 hangs more often than not when running ‘rails c’.
I don’t know if this is the same bug, and while it is an odd scenario, it is 100% reproducible with Rails 5.1, Spring 2.0.2, and Mac OS/X High Sierra:
Generally, control-C isn’t enough to stop the process, it requires killing. Once killed, retrying the generate scaffold command once again hangs, unless a
spring stop
is done before then (yes, in the newly recreated project directory).Hope this helps.
After a lot of tinkering I was able to figure out why it happens, at least in my case.
First, Spring hangs when checking out a branch that has changes in one of the monitored files:
Gemfile
or config files. In this case Spring reloads an application on background. If your application prints any warnings on initialise the process will wait to accessSTDOUT
which never happens as Spring’sapplication
process runs on background. In my case the solution was to disable warnings with$VERBOSE=nil
on top of theconfig/application.rb
because the app wasn’t trying to print anything but warnings. But of course it won’t do if you want to keep seeing warnings.Kind of related, and kind of good news: Spring is not default anymore https://github.com/rails/rails/pull/42997
Jan 2021, it’s seems the issue still exists. When I start rails c, I see a ruby proccess that comsumes 100% cpu. The proccess is not killed even I exit rails c
Okay, I’ve played with it a little and here’s what I found. Spring freezes during eager preload. That happens when PTY that we provided gets written more than X bytes without being read from the other end. Normally, we would read that using the other thread that we spawn. However, when ruby issues warnings like “previous definition of XXX was here”, it uses blocking writes. Blocking write starts writing and PTY gets clogged. We can’t do anything until we read something. But our reader is in the parallel thread. Which we never get to because we’re currently trying to write something to stderr.
I don’t know enough about why pty was introduced in the first place, however, as a workaround, I’m going to redirect
STDERR
to/dev/null
in situations when we can’t see it (e.g. preloading in the background).Hope that made any sense.
I’m still seeing this problem with the new spring release 2.1.1.
rails test
hangs butbin/rails test
works fine for me 👍hangs a lot … on ruby 2.5, rails 5.1.3 tried both spring 1.7.2 and 2.0.2
We still see a lot of slowdowns on the initial boot after upgrading to Rails 5 and spring 2.
rails (5.0.1) spring (2.0.1) spring-commands-rspec (1.0.4) spring-commands-rubocop (0.2.0) spring-watcher-listen (2.0.1)
DISABLE_SPRING=1 rails console
takes about 8 seconds.rails console
takes 75 seconds (1:15m). Subsequent calls are fast, since spring is now running.Is there a way to have spring verbosely output what it’s doing and find where it’s hanging?
I also noticed that a new Rails 5.0 applications hangs and freezes and could not solve the problem for weeks until I commented out the
spring
gem. It only appeared in development environment where thespring
gem was included. The normal logs say nothing, the application just hangs, which is extremely nasty and annoying.I am having the same issue (I do have dnsruby gem in my project), either with @markiz solution or 1.7.2 version. Anyone else seeing the same?
Experienced similar hanging with every “rails”-command on Rails 6.1.5 and after trying all kind of sorcery and witchcraft I ended up regenerating binstubs with “rake app:update:bin”. This solved all “rails”-command issues for me.
Worked. Thank you 👍
Not to pile on, but this is definitely reproducible with a minimal rails application.
Tested this with Ruby 3.0.0 but have seen the same behavior for a long time with other ruby versions.
I tried with the #693 fork changes and it didn’t seem to fix this particular issue.
I did find something just now that might be interesting/relevant: this error only happens when I’m inside tmux. I wonder how many other people in this thread are using tmux?
I typically have no other problems with tmux and tmux itself isn’t hung up; even when it hangs I can create a new buffer & then issue
pkill -9 ruby
to kill the hanging processEdit: I’ve also tried updating the listen gem and have seen mixed results
Edit 2: I’ve tested a modified version of my commands above inside of tmux; newest stable ruby + rails + manually activate & install spring + manually start spring. The patch noted at the bottom of this thread in #623 appears to fix it. Spring no longer hangs in tmux; it raises the correct/expected “key not found” error message
I’m having the exact same problem with Rails 5.0.2 and Spring 2.0.2 on my mac. When I run
rails console
the process hangs, I can’t stop it with CMD+C, and I have to kill the process with the kill command. Sometimes the kill command is not enough and I have to restart my mac or comment out the spring gem.I did a bunch of debugging today on an app where spring was nearly unusable and it turns out that removing the
dnsruby
gem from the Gemfile solved the problem. Not sure what the cause of the issue is (could be related to the use oftimeout
) but hope this helps someone.Ctrl+C won’t get me out of it, either. I have to kill the process from elsewhere.
I had spring hang regularly, sometimes every five minutes. I’ve manually applied the patch in https://github.com/markiz/spring/commit/5f3ab734fc45d541aaaccb05b59cd95aa49fe8ef and haven’t seen any hangs since. As per https://github.com/rails/spring/issues/396#issuecomment-248906237 I’m going to submit that patch as a PR. Conveniently, it’s also on a branch.
Try Zeus instead - https://github.com/burke/zeus We’ve been using it for a more than a year in our workplace. It’s not perfect, but more stable than Spring at least.
This is happening all the time for a private project that I work on. Here’s how I can recreate it at will:
Terminal 1
spring stop; spring server;
Terminal 2
rails runner 'puts 1 + 1'
touch config/application.rb
You will see a
socket closed
exception logged to terminal 1 and the spring server will hang. Any subsequent spring commands will hang indefinitely.This isn’t the case for all projects though 😞
You can try my fix: https://github.com/rails/spring/pull/484. It should help with hanging
rails console
😃