0

I've got a flask API application running on Win by apache + mod_wsgi plugin. I made a grpc service by official tutorials, created grpc server and running it as a win service (by some win service manager, can't find it anymore). As grpc client i used a flask endpoint:

@web.route( '/services/<service_name>', methods=[ 'POST' ] )
def run_service( service_name ):
    #flask response object, little desinged
    resp = EmptyResp()
    try:
        chan = grpc.insecure_channel( 'my.secret.ip:6066' )
        stub = rpc.gen.services_pb2_grpc.ServicesStub( chan )
        #here just trying to find existed method, they got an Empty messasge, can't find a good solution
        rpcResp = stub.__getattribute__( service_name )( rpc.gen.services_pb2.Empty() )
        #my func to decorate response
        resp.data = ObjResp( rpcResp.state )
    except NameError as NErr:
        print( NErr )
        resp.status_code = 404
        resp.data = ErrResp( 'Cannot get RPC generated files')
    except AttributeError as AErr:
        print( AErr )
        resp.status_code = 404
        resp.data = ErrResp( 'Where is no \'%s\' method or problem with RPC files' % service_name )
    except grpc._channel._InactiveRpcError as ErrConnRPC:
        print( ErrConnRPC )
        resp.status_code = 503
        resp.data = ErrResp( 'Cannot connect with RPC service' )
    finally:
        chan.close()
    return resp

So, the problem is that first request to that endpoint is completes with 200 and return of RPC method. But further requests to any endpoint of api are not responding at all. No HTTP timeout error, no crushes of application at all, no attemts to run a flask or gRPC methods (i used print() for that). Just infinite loading. Repairs only by restarting both gRPC and Apache services.

I cannot find any solution to deploy gRPC servers, somy questions are: 1) What the reason why 2+ requests are not responding; 2) What is correct way to deploy gRPC servers on Win? 3) [Optional] In this row: stub.__getattribute__( service_name )( rpc.gen.services_pb2.Empty() ) is there an option to do it better way?

Sas Matras
  • 31
  • 1
  • 3
  • There's nothing obviously suspicious with your gRPC code (except the usage of the private `_InactiveRpcError`class). What is your application doing when it's unresponsive to requests? – Richard Belleville Apr 29 '20 at 17:50

1 Answers1

0

There are issues running grpc clients with apache + mod_wsgi, the reason seems because of how processes are forked (and there are known issues with grpc-python on forking)

Refs: https://github.com/grpc/grpc/issues/13050

sine
  • 16
  • 1