Unicorn with Ruby 2.4.1 causing weird crash
Asked Answered
V

1

7

I am upgrading from Ruby 2.3.1 to Ruby 2.4.1 and upon doing so Unicorn seems be incompatible with the new version. I get the errors below. I am using Unicorn 5.1.0 and have tried Unicorn 5.3.1 to no avail. Do I need to compile with a different lib instead of XCode Tools?

I get the error immediately upon starting the server with foreman start and the Procfile:

webpack: bin/webpack-dev-server
gulp: gulp
redis: ./scripts/start_redis_server.sh
sidekiq: bundle exec sidekiq -C config/sidekiq.yml
annotations_server: ./scripts/start_annotation_server.sh
rails: bundle exec unicorn_rails -p 3000 -c config/unicorn.rb

It seems to start and run fine if I use a simple bin/rails s which I why I think it is specific to Unicorn.

objc[40847]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called.
objc[40846]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called.
objc[40846]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
objc[40847]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
E, [2017-10-05T12:12:01.618013 #40833] ERROR -- : reaped #<Process::Status: pid 40847 SIGABRT (signal 6)> worker=1
E, [2017-10-05T12:12:01.618064 #40833] ERROR -- : reaped #<Process::Status: pid 40846 SIGABRT (signal 6)> worker=0
I, [2017-10-05T12:12:01.619387 #40850]  INFO -- : Refreshing Gem list
I, [2017-10-05T12:12:01.620867 #40851]  INFO -- : Refreshing Gem list
Vange answered 5/10, 2017 at 17:23 Comment(2)
There's really not a lot of information here. Under what circumstances do you get this crash?Redraft
Just starting the local dev server. Ill update the question with a few more details.Vange
V
21

MacOS High Sierra changed the behaviour of the fork syscall such that calls to Objective-C APIs in forked processes are treated as errors.

When using Ruby on macOS High Sierra, this is what is used By Ruby. The same issue also affects Puma and other servers using a multi-process model and is thus not strictly a Unicorn (or Puma) issue, but one of Ruby.

The issue was discussed on the Unicorn mailing list and on a Puma issue.

If you need to stick to your old Ruby version for any reason, as a workaround, you can add the following environment variable before starting the Ruby process:

OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

Preferably, you should update to Ruby 2.4.4 or higher (including 2.5 and 2.6). These versions include the fix for this issue in Ruby itself and you don't need to set the environment variable anymore.

Veilleux answered 5/10, 2017 at 20:0 Comment(2)
I'll check this out in a bit and accept it after verifying, thanks for the thorough response.Vange
Where do I add that environment variable? I tried entering it before I ran my tests, as well as putting it in my config/environment.rb file, and neither fixed the objc messages.Bijou

© 2022 - 2024 — McMap. All rights reserved.