-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ruby: grpc v1.48.0+ crashes on macOS in pre-forking app servers #33281
Comments
This prevents a crash on macOS that occurs if Objective C calls are made after a process is forked. This ensures that the Apple system call `CFTimeZoneCopyDefault` is invoked first in the parent process, which prevents macOS from killing the child process with the message: ``` +[__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. ``` Closes grpc#33281
This prevents a crash on macOS that occurs if Objective C calls are made after a process is forked. This ensures that the Apple system call `CFTimeZoneCopyDefault` is invoked first in the parent process, which prevents macOS from killing the child process with the message: ``` +[__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. ``` Closes grpc#33281
This prevents a crash on macOS that occurs if Objective C calls are made after a process is forked. This ensures that the Apple system call `CFTimeZoneCopyDefault` is invoked first in the parent process, which prevents macOS from killing the child process with the message: ``` +[__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. ``` Closes grpc#33281
This prevents a crash on macOS that occurs if Objective C calls are made after a process is forked. This ensures that the Apple system call `CFTimeZoneCopyDefault` is invoked first in the parent process, which prevents macOS from killing the child process with the message: ``` +[__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. ``` Closes grpc#33281
This prevents a crash on macOS that occurs if Objective C calls are made after a process is forked. This ensures that the Apple system call `CFTimeZoneCopyDefault` is invoked first in the parent process, which prevents macOS from killing the child process with the message: ``` +[__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. ``` Closes grpc#33281
This prevents a crash on macOS that occurs if Objective C calls are made after a process is forked. This ensures that the Apple system call `CFTimeZoneCopyDefault` is invoked first in the parent process, which prevents macOS from killing the child process with the message: ``` +[__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. ``` Closes grpc#33281
This prevents a crash on macOS that occurs if Objective C calls are made after a process is forked. This ensures that the Apple system call `CFTimeZoneCopyDefault` is invoked first in the parent process, which prevents macOS from killing the child process with the message: ``` +[__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. ``` Closes grpc#33281
This prevents a crash on macOS that occurs if Objective C calls are made after a process is forked. This ensures that the Apple system call `CFTimeZoneCopyDefault` is invoked first in the parent process, which prevents macOS from killing the child process with the message: ``` +[__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. ``` Closes grpc#33281
This prevents a crash on macOS that occurs if Objective C calls are made after a process is forked. This ensures that the Apple system call `CFTimeZoneCopyDefault` is invoked first in the parent process, which prevents macOS from killing the child process with the message: ``` +[__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. ``` Closes grpc#33281
Hi, are there any plans to make a fix here? I can reproduce with the following versions:
This happens any time a grpc server returns an error response, which makes grpc completely unusable in development. The workaround shared above doesn't work for me, as running All I could do for now was pin to v1.47, which works but doesn't seem sustainable. Thanks! |
Are you sure you are calling this before the process forks? I tried to fix this in #33400, but calling |
Pretty sure! I'm actually opening a Rails console and running it immediately. |
Can you show the exact error messages you're seeing? You might also want to attach the program to |
Did #33430 help this in any way? |
What version of gRPC and what language are you using?
Tested in v1.48.0 - v1.55.0 with Ruby 3.1.4
What operating system (Linux, Windows,...) and version?
macOS Ventura 13.4
What runtime / compiler are you using (e.g. python version or version of gcc)
Ruby v3.1.4
What did you do?
After upgrading to
grpc
v1.48.0, the Puma app server crashes after issuing a call:This is related to #31240 for Python. The statement to avoid os.fork() in macOS is not really practical. We have been running preforking app servers like Puma and Unicorn for years in production on Linux servers, and making our development environment completely different from production does not make sense.
Other related links:
What did you expect to see?
No crash.
What did you see instead?
If I compile the v1.48.0 gem with
GRPC_CONFIG=dbg
and attachlldb
to the worker process, I see this backtrace:Workaround
The main problem appears to be that
abseil-cpp
lazily callsCFTimeZoneCopyDefault
in https://github.com/abseil/abseil-cpp/blob/78be63686ba732b25052be15f8d6dee891c05749/absl/time/internal/cctz/src/time_zone_lookup.cc#L139. IfCFTimeZoneCopyDefault
is first called inside a forked child process, macOS kills the process.I worked around this problem by calling
CFTimeZoneCopyDefault
in a pre-fork block:Note that the
CoreFoundation
library loading could likely be dropped now that https://bugs.ruby-lang.org/issues/14009 is closed.Proposal
I suspect if
absl::InitializeLog()
were called in a pre-fork block, we'd be able to avoid this. I'd propose we add some initialize function for Ruby and Python that can be called to ensure any OS-dependent setup happens before gRPC operations begin.The text was updated successfully, but these errors were encountered: