Skip to content

gRPC server on Python 3.6 is incompatible with os.fork() #17093

@dcoles

Description

@dcoles

What version of gRPC and what language are you using?

gRPC 1.16.0 for Python

What operating system (Linux, Windows, …) and version?

Ubuntu 18.04 LTS (4.15.13-x86_64-linode106) for x86_64

What runtime / compiler are you using (e.g. python version or version of gcc)

Python 3.6.5

What did you do?

  1. Checkout the python/helloworld/greeter_server.py example
  2. Add code that calls fork() to the handler
  3. Start the server with python3 greeter_server.py
  4. Run python3 greeter_client.py multiple times

This seems to be the root cause of #14436.

What did you expect to see?

$ python greeter_client.py
Greeter client received: Hello, you!
$ python greeter_client.py
Greeter client received: Hello, you!

What did you see instead?

NOTE: These examples work correctly under Python 2.7 or if using subprocess without a preexec_fn (does not cause _posixsubprocess to call back into Python).

On the server:

$ python3.6 greeter_server_preexec.py
E1104 01:27:37.862233836   24328 tcp_server_posix.cc:210]    Failed accept4: Invalid argument

On the client:

$ python greeter_client.py
Traceback (most recent call last):
  File "greeter_client.py", line 35, in <module>
    run()
  File "greeter_client.py", line 30, in run
    response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
  File "/home/dcoles/workspace/grpc/grpc/examples/python/helloworld/venv/local/lib/python3.6/site-packages/grpc/_channel.py", line 533, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/home/dcoles/workspace/grpc/grpc/examples/python/helloworld/venv/local/lib/python3.6/site-packages/grpc/_channel.py", line 467, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.INTERNAL
        details = "Received RST_STREAM with error code 2"
        debug_error_string = "{"created":"@1541294857.862411425","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1017,"grpc_message":"Received RST_STREAM with error code 2","grpc_status":13}"
>
$ python greeter_client.py
Traceback (most recent call last):
  File "greeter_client.py", line 35, in <module>
    run()
  File "greeter_client.py", line 30, in run
    response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
  File "/home/dcoles/workspace/grpc/grpc/examples/python/helloworld/venv/local/lib/python3.6/site-packages/grpc/_channel.py", line 533, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/home/dcoles/workspace/grpc/grpc/examples/python/helloworld/venv/local/lib/python3.6/site-packages/grpc/_channel.py", line 467, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "Connect Failed"
        debug_error_string = "{"created":"@1541294859.542303123","description":"Failed to create subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":2721,"referenced_errors":[{"created":"@1541294859.542300691","description":"Pick Cancelled","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":241,"referenced_errors":[{"created":"@1541294859.542285256","description":"Connect Failed","file":"src/core/ext/filters/client_channel/subchannel.cc","file_line":689,"grpc_status":14,"referenced_errors":[{"created":"@1541294859.542274056","description":"Failed to connect to remote host: OS Error","errno":111,"file":"src/core/lib/iomgr/tcp_client_posix.cc","file_line":205,"os_error":"Connection refused","syscall":"connect","target_address":"ipv4:127.0.0.1:50051"}]}]}]}"
>

Anything else we should know about your project / environment?

gRPC for Python 2.7 and 3.6 was installed using pip to ensure I was using the latest version.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions