使用Ruby 2.4.1的Unicorn导致奇怪的崩溃

时间:2017-10-05 17:23:17

标签: ruby unicorn

我正在从Ruby 2.3.1升级到Ruby 2.4.1,因此Unicorn似乎与新版本不兼容。我得到以下错误。我正在使用Unicorn 5.1.0并尝试使用Unicorn 5.3.1无济于事。我是否需要使用不同的lib而不是XCode Tools进行编译?

我使用foreman start和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

如果我使用一个简单的bin/rails s,它似乎开始并运行正常,我认为它是针对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

1 个答案:

答案 0 :(得分:20)

MacOS High Sierra changed the behaviour of the fork syscall,以便在分叉进程中调用Objective-C API被视为错误。

在macOS High Sierra上使用Ruby时,这就是Ruby使用的内容。同样的问题也会影响使用多进程模型的Puma和其他服务器,因此不是严格意义上的Unicorn(或Puma)问题,而是Ruby之一。

问题已在Unicorn mailing listPuma issue上进行了讨论。

如果您出于任何原因需要坚持使用旧的Ruby版本,作为一种变通方法,您可以在启动Ruby过程之前添加以下环境变量:

i

最好,您应该更新到Ruby 2.4.4或更高版本(包括2.5和2.6)。这些版本包含the fix这个问题在Ruby本身,您不再需要设置环境变量。