-
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
Clearly document the cases where fork() is supported in grpc() #14055
Comments
Reassigning to @kpayson64 . |
I noticed a fork.h header. does it provide the support for fork? void grpc_prefork(); Thanks. |
That is the intention but first this bug needs to be fixed to do fork/exec. @zhanghaohit what is your use case? |
My use case is: But after the child process finished its job, it just exists. Then the main process will fork a new child process again. So I have to fork multiple times from the main process. @srini100 Can I achieve this in the current grpc implementation? Do I have to destroy the Stub instance and re-create in the child process? Thanks. |
@zhanghaohit, forking with an active stub will put you in a situation where parent and child will share the same connection. gRPC currently doesn't cleanup FDs in child process. IMO, recreating the stub in child process should work. |
@srini100 Thanks for your reply. Yes. I did recreate the stub in the child process. In my case, do I need to call grpc_prefork(), grpc_postfork_parent(), grpc_postfork_child() also? But anyway, no matter I call grpc_fork_ or not, it will hang there after second fork. |
These functions are called internally by gRPC. You shouldn't call these. |
Oh. ic. but still cannot get it to work by recreating the stub in the child process. It will hang after the second fork. |
Closed via #14870 |
gRPC does not support
fork()
in general - i.e it is not safe for a gRPC application to callfork()
as it can lead to undefined behavior.As of release 1.7, we added very limited support to
fork()
; where it is safe for an application to callfork()
as long as the application did not start any gRPC work (beyond callinggrpc_init()) prior to calling
fork()`We need to do a better job at documenting this clearly - the fact that gRPC does not support fork() in general and the only time it is safe to call fork() is if the application did not start any gRPC work.
We have been noticing several issues caused due to fork() (and this is mainly due to grpc users not realizing that fork() is not supported)
The text was updated successfully, but these errors were encountered: