spring icon indicating copy to clipboard operation
spring copied to clipboard

Prevent server crash by restarting child

Open prognostikos opened this issue 1 year ago • 2 comments

Before this change, if Errno::EINVAL is thrown when sending IO to the child the server would crash. Now we catch the exception and, assuming the child has problems, we start a new child.

prognostikos avatar Sep 12 '24 09:09 prognostikos

This is a solution, or maybe better characterized as a work-around, for #716

Before this change, in a Rails 7.0.8.4 app using ruby 3.3.4 (2024-07-09 revision be1089c8ec) [arm64-darwin23] I could trigger the error as follows:

  1. start spring using spring server in one terminal
  2. start rails c in a second terminal
  3. run rails db:migrate:status in a third terminal - it succeeds
  4. run touch config/initializers/content_security_policy.rb in the third terminal
  5. run rails db:migrate:status in the third terminal - it hangs with no output and the console running in the second terminal is dead.
  6. in the first terminal, spring dies with lib/spring/application_manager.rb:64:in `send_io': Invalid argument - sendmsg(2) (Errno::EINVAL)

I have put the spring server logs for both the error and fixed versions here: https://gist.github.com/prognostikos/0d07e599516e51ddc355134e13c94a95

I would love to get this into a new Spring release, what needs to be done for that to happen? I can see there are some issues with CI, and running the acceptance tests locally with RAILS_VERSION="edge" also seems to hang so there is probably a bit of work to do on the test setup.

prognostikos avatar Sep 12 '24 10:09 prognostikos

This seems to fix the problems I encountered in #716 👍

fschwahn avatar Sep 16 '24 07:09 fschwahn

Could this get attention from the Maintainers ? It's a very simple patch that solves a very annoying problem

fmichaut-diff avatar May 16 '25 21:05 fmichaut-diff

Thanks for the fix, @prognostikos ❤️ And cheers for the merge, @rafaelfranca! I would love to see a release with this 🙏

Edit: I've been using this branch for a month. I was seeing freezing the issue daily before that, and have not seen it since; so can confirm it works

Edit 2: Now released in 4.4.0 🎉

ZimbiX avatar Aug 02 '25 13:08 ZimbiX