Skip to content
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

Closed
sreecha opened this issue Jan 18, 2018 · 9 comments
Closed

Clearly document the cases where fork() is supported in grpc() #14055

sreecha opened this issue Jan 18, 2018 · 9 comments
Assignees

Comments

@sreecha
Copy link
Contributor

sreecha commented Jan 18, 2018

gRPC does not support fork() in general - i.e it is not safe for a gRPC application to call fork() 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 call fork() as long as the application did not start any gRPC work (beyond calling grpc_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)

@sreecha
Copy link
Contributor Author

sreecha commented Feb 6, 2018

Reassigning to @kpayson64 .

@zhanghaohit
Copy link

I noticed a fork.h header. does it provide the support for fork?

void grpc_prefork();
void grpc_postfork_parent();
void grpc_postfork_child();

Thanks.

@srini100
Copy link
Contributor

That is the intention but first this bug needs to be fixed to do fork/exec.

@zhanghaohit what is your use case?

@zhanghaohit
Copy link

zhanghaohit commented Mar 13, 2018

My use case is:
I have to fork a new process, which will take over the job from the main process. It means, after the forking, the main process will not do anything with grpc.

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.

@srini100
Copy link
Contributor

@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.

@zhanghaohit
Copy link

@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.

@srini100
Copy link
Contributor

These functions are called internally by gRPC. You shouldn't call these.

@zhanghaohit
Copy link

Oh. ic. but still cannot get it to work by recreating the stub in the child process. It will hang after the second fork.

@kpayson64
Copy link
Contributor

Closed via #14870

@lock lock bot locked as resolved and limited conversation to collaborators Sep 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants