Skip to content

Work around macOS forking issues with grpc gem update

Stan Hu requested to merge sh-add-macos-workaround-for-grpc-update into master

What does this MR do and why?

With the update of the grpc gem to v1.55.0, it appears that after a grpc connection is completed, the status is parsed, and the timestamp is formatted with the local time zone. The underlying C++ library, abseil-cpp, appears to call Apple system APIs to retrieve the local time zone (https://github.com/abseil/abseil-cpp/blob/78be63686ba732b25052be15f8d6dee891c05749/absl/time/internal/cctz/src/time_zone_lookup.cc#L139). However, macOS will crash the Puma process if these system APIs are called within a fork.

We currently have a workaround for macOS (https://bugs.ruby-lang.org/issues/14009) that prevents the crash for the Foundation framework. However, not only does the the grpc update need the CoreFoundation framework, but it also needs to call CFTimeZoneCopyDefault to load the default time zone. We now use the ffi gem to load the default time zone and release the resource to avoid this crash, as reported in https://github.com/grpc/grpc/issues/26257.

Relates to #413536 (closed)

How to set up and validate locally

  1. On master, create a file inside a project. You should see a crash if you gdk tail rails-web:
2023-05-30_17:04:54.01856 rails-web             : objc[60607]: +[__NSTimeZone initialize] may have been in progress in another thread when fork() was called.
2023-05-30_17:04:54.01926 rails-web             : objc[60607]: +[__NSTimeZone 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.
  1. Check out this branch and repeat. The crash should stop.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Stan Hu

Merge request reports