spring icon indicating copy to clipboard operation
spring copied to clipboard

Spring 4.2.0 crashing when running rake

Open fschwahn opened this issue 9 months ago • 7 comments

This happened to me when running rails db:migrate.

I have never seen this before, and I have been using spring daily for years. Maybe it is connected to the changes in 4.2.0 (namely #708).

I'm running spring server as a separate process, so I have logs / stacktrace to share:

15:50:59 spring.1 | [2024-04-26 15:50:59 +0200] [4120] [server] accepted client
15:50:59 spring.1 | [2024-04-26 15:50:59 +0200] [4120] [server] running command rake
15:50:59 spring.1 | [2024-04-26 15:50:59 +0200] [4120] [server] shutting down
15:50:59 spring.1 | [2024-04-26 15:50:59 +0200] [4120] [application_manager:development] stopping
15:50:59 spring.1 | [2024-04-26 15:50:59 +0200] [4120] [application_manager:test] stopping
15:50:59 spring.1 | [2024-04-26 15:50:59 +0200] [12426] [application:development] forced exit
15:50:59 spring.1 | /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/application_manager.rb:63:in `send_io': Invalid argument - sendmsg(2) (Errno::EINVAL)
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/application_manager.rb:63:in `block in run'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/application_manager.rb:44:in `block in with_child'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/application_manager.rb:22:in `synchronize'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/application_manager.rb:41:in `with_child'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/application_manager.rb:62:in `run'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/server.rb:70:in `serve'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/server.rb:51:in `block in start_server'
15:50:59 spring.1 | 	from <internal:kernel>:187:in `loop'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/server.rb:51:in `start_server'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/server.rb:45:in `boot'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/server.rb:14:in `boot'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/client/server.rb:10:in `call'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/client/command.rb:7:in `call'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/client.rb:30:in `run'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/bin/spring:49:in `<top (required)>'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/binstub.rb:5:in `load'
15:50:59 spring.1 | 	from /Users/fabian/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/spring-4.2.0/lib/spring/binstub.rb:5:in `<top (required)>'
15:50:59 spring.1 | 	from <internal:/Users/fabian/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
15:50:59 spring.1 | 	from <internal:/Users/fabian/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
15:50:59 spring.1 | 	from bin/spring:12:in `block in <main>'
15:50:59 spring.1 | 	from <internal:kernel>:90:in `tap'
15:50:59 spring.1 | 	from bin/spring:9:in `<main>'

fschwahn avatar Apr 26 '24 14:04 fschwahn

Also running into this issue on MacOS.

This happens to me when the spring server is running, but a change gets detected by the watchers (eg: changing a config/ file).

The next client to connect to the server will trigger that error, killing the server process and any live pre-existing client and will make the new client hang indefinitely on preload_status = application.gets.

This is very frustrating when working on a git project, cause every change of branch is likely to trigger a watcher, which breaks the spring server and kills any open session (eg: a rails console being used, open a new terminal to run a rails db:migrate, rails g migration, or even another rails c will kill the running console, and the new process will hang indefinitely and won't even respond to CTRL-C)

I've been running into that issue for months now, it would be great if it could get fixed.

Relates to https://github.com/rails/spring/issues/396, https://github.com/rails/spring/issues/663, looks like this issue is very resilient

fmichaut-diff avatar Jul 11 '24 18:07 fmichaut-diff

@fschwahn @fmichaut-diff I have a fix/workaround for this in #727

You could try it out to see if it fixes your issue, I have done so by using bundle open and applied the patch in the pr, as spring doesn't support being run as gem "spring", git: "..."

Would love to hear if it works with your version of rails, ruby, os, etc.

prognostikos avatar Sep 13 '24 08:09 prognostikos

Or as noted in CONTRIBUTING.md you can use rake install to test the change.

prognostikos avatar Sep 13 '24 08:09 prognostikos

I was able to reproduce reliably using your steps, and after applying your patch it no longer happens. I will now run this patch locally.

fschwahn avatar Sep 16 '24 07:09 fschwahn

I was able to reproduce reliably using your steps, and after applying your patch it no longer happens. I will now run this patch locally.

Thanks @fschwahn. If you have a moment to list the versions of your OS, ruby and rails that would be helpful. I'm interested to know if the fix works for more than just for my versions.

prognostikos avatar Sep 16 '24 08:09 prognostikos

OS: macOS 14.6.1 Ruby: 3.3.5 Rails: 7.1.3.4

fschwahn avatar Sep 16 '24 09:09 fschwahn

I have been testing since yesterday, and things are looking good so far ! Thanks

OS: MacOS 14.6.1 Ruby: 3.3.0 Rails: 7.2.1

fmichaut-diff avatar Sep 19 '24 18:09 fmichaut-diff