Ruby 2.4.1 的独角兽导致奇怪的崩溃
Unicorn with Ruby 2.4.1 causing weird crash
我正在从 Ruby 2.3.1 升级到 Ruby 2.4.1,这样做之后,Unicorn 似乎与新版本不兼容。我收到以下错误。我正在使用 Unicorn 5.1.0 并尝试过 Unicorn 5.3.1 无济于事。我是否需要使用不同的库而不是 XCode 工具进行编译?
我在使用 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
MacOS High Sierra changed the behaviour of the fork
syscall 这样在分叉进程中对 Objective-C API 的调用将被视为错误。
在 macOS High Sierra 上使用 Ruby 时,这是 Ruby 使用的内容。同样的问题也影响 Puma 和其他使用多进程模型的服务器,因此严格来说不是 Unicorn(或 Puma)问题,而是 Ruby.
之一
Unicorn mailing list and on a Puma issue 上讨论了这个问题。
如果您出于任何原因需要坚持使用旧的 Ruby 版本,作为解决方法,您可以在开始 Ruby 进程之前添加以下环境变量:
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
您最好更新到 Ruby 2.4.4 或更高版本(包括 2.5 和 2.6)。这些版本在 Ruby 本身包含针对此问题的 the fix,您不再需要设置环境变量。
我正在从 Ruby 2.3.1 升级到 Ruby 2.4.1,这样做之后,Unicorn 似乎与新版本不兼容。我收到以下错误。我正在使用 Unicorn 5.1.0 并尝试过 Unicorn 5.3.1 无济于事。我是否需要使用不同的库而不是 XCode 工具进行编译?
我在使用 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
MacOS High Sierra changed the behaviour of the fork
syscall 这样在分叉进程中对 Objective-C API 的调用将被视为错误。
在 macOS High Sierra 上使用 Ruby 时,这是 Ruby 使用的内容。同样的问题也影响 Puma 和其他使用多进程模型的服务器,因此严格来说不是 Unicorn(或 Puma)问题,而是 Ruby.
之一Unicorn mailing list and on a Puma issue 上讨论了这个问题。
如果您出于任何原因需要坚持使用旧的 Ruby 版本,作为解决方法,您可以在开始 Ruby 进程之前添加以下环境变量:
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
您最好更新到 Ruby 2.4.4 或更高版本(包括 2.5 和 2.6)。这些版本在 Ruby 本身包含针对此问题的 the fix,您不再需要设置环境变量。