forking child process in server causes client handshake failures

75 views
Skip to first unread message

AK

unread,
Mar 7, 2017, 12:40:27 PM3/7/17
to grpc.io

I am trying to make grpc server a daemon by forking a child and making it exit. But after that the client handshake starts to fail.

E0307 01:15:58.221786152   27094 handshake.c:128]            Security handshake failed: {"created":"@1488878158.221756436","description":"Handshake read failed","file":"src/core/lib/security/transport/handshake.c","file_line":237,"referenced_errors":[{"created":"@1488878158.221740996","description":"FD shutdown","file":"src/core/lib/iomgr/ev_epoll_linux.c","file_line":948}]}

This happens if fork() is called after the call to BuildAndStart(). If the same fork is done before BuildAndStart() everything works fine.

Nicolas Noble

unread,
Mar 7, 2017, 3:07:40 PM3/7/17
to AK, grpc.io
Does the forked child do any gRPC call at all ? Also, which language ?

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/1d59f06c-bdad-4a00-9f01-1abcd59a7cbc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

AK

unread,
Mar 7, 2017, 3:19:44 PM3/7/17
to grpc.io, anand.s...@gmail.com
The forked child simply exits leaving the parent as daemon. I am doing it in C++ on Ubuntu.


On Tuesday, March 7, 2017 at 12:07:40 PM UTC-8, Nicolas Noble wrote:
Does the forked child do any gRPC call at all ? Also, which language ?
On Tue, Mar 7, 2017 at 9:40 AM, AK <anand.s...@gmail.com> wrote:

I am trying to make grpc server a daemon by forking a child and making it exit. But after that the client handshake starts to fail.

E0307 01:15:58.221786152   27094 handshake.c:128]            Security handshake failed: {"created":"@1488878158.221756436","description":"Handshake read failed","file":"src/core/lib/security/transport/handshake.c","file_line":237,"referenced_errors":[{"created":"@1488878158.221740996","description":"FD shutdown","file":"src/core/lib/iomgr/ev_epoll_linux.c","file_line":948}]}

This happens if fork() is called after the call to BuildAndStart(). If the same fork is done before BuildAndStart() everything works fine.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

Ken Payson

unread,
Mar 7, 2017, 4:03:01 PM3/7/17
to AK, grpc.io
Are you calling any destructors in the forked process before exit?  Destroying the server will call shutdown() on the underlying sockets, which will cause problems for the parent process.

Ken

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.

AK

unread,
Mar 7, 2017, 4:32:26 PM3/7/17
to grpc.io, anand.s...@gmail.com
No. The child does nothing but exit. Below is an example of what I am doing. If I move the server startup line to the end, everything works fine.

   server = std::unique_ptr<grpc::Server>(builder.BuildAndStart());
   int childpid = fork();
    if ( childpid )
      exit(0);



On Tuesday, March 7, 2017 at 1:03:01 PM UTC-8, Ken Payson wrote:
Are you calling any destructors in the forked process before exit?  Destroying the server will call shutdown() on the underlying sockets, which will cause problems for the parent process.

Ken
On Tue, Mar 7, 2017 at 12:19 PM, AK <anand.s...@gmail.com> wrote:
The forked child simply exits leaving the parent as daemon. I am doing it in C++ on Ubuntu.

On Tuesday, March 7, 2017 at 12:07:40 PM UTC-8, Nicolas Noble wrote:
Does the forked child do any gRPC call at all ? Also, which language ?

On Tue, Mar 7, 2017 at 9:40 AM, AK <anand.s...@gmail.com> wrote:

I am trying to make grpc server a daemon by forking a child and making it exit. But after that the client handshake starts to fail.

E0307 01:15:58.221786152   27094 handshake.c:128]            Security handshake failed: {"created":"@1488878158.221756436","description":"Handshake read failed","file":"src/core/lib/security/transport/handshake.c","file_line":237,"referenced_errors":[{"created":"@1488878158.221740996","description":"FD shutdown","file":"src/core/lib/iomgr/ev_epoll_linux.c","file_line":948}]}

This happens if fork() is called after the call to BuildAndStart(). If the same fork is done before BuildAndStart() everything works fine.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/1d59f06c-bdad-4a00-9f01-1abcd59a7cbc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.

Ken Payson

unread,
Mar 7, 2017, 4:47:52 PM3/7/17
to AK, grpc.io
I'm not familiar with the interaction of unique_ptr<> and exit().

What happens if you try the following:

   grpc::Server* server_ptr = builder.BuildAndStart();

   int childpid = fork();
    if ( childpid )
      exit(0);
   server = std::unique_ptr<grpc::Server>(server_ptr);


Also, in the problem you stated, it sounded like you were forking and exiting the child immediately.  The code provided exits the parent process immediately.



To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.

AK

unread,
Mar 7, 2017, 5:08:43 PM3/7/17
to grpc.io, anand.s...@gmail.com
You are right about parent exiting. Sorry, that might have caused confusion. Actually the child becomes daemon now. Does that change how secure handshake in grpc behaves ?
The builder.BuildAndStart() returns std::unqiue_ptr.
Your suggested changes seems to make no difference to process state.

Ken Payson

unread,
Mar 7, 2017, 5:14:36 PM3/7/17
to AK, grpc.io
If you are forking and exiting the parent immediately, I'd suggest avoid doing any gRPC setup in the parent process.

The suggested changes were intended to avoid invoking the Server destructor.  I suspect whats happening is std::unique_ptr<> is causing the destructor to be called on exit().

That being said, I'd still recommend deferring server construction to the child process.

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
Reply all
Reply to author
Forward
0 new messages