huntlabs / grpc-dlang

Grpc for D programming language, hunt-http library based.
Apache License 2.0
44 stars 6 forks source link

have trouble to use D grpc client to talk to Python grpc server #15

Open mw66 opened 4 years ago

mw66 commented 4 years ago

Hi,

I'm trying the helloworld example, but I'm using a Python server, something like this:

import grpc
import HW_pb2
import HW_pb2_grpc

if __name__ == "__main__":
  handler = HWHandler()
  server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
  HW_pb2_grpc.add_HWServicer_to_server(handler, server)
  server.add_insecure_port('[::]:' + str(PORT))
  server.start()

And then use the D grpc client talk to it, the 1st time I run it: I got:

Thread 11 "" received signal SIGSEGV, Segmentation fault.                
[Switching to Thread 0x7fffcf7fe700 (LWP 2892)]                                                                
0x0000555555aca53c in _D4hunt4http6client18Http1ClientDecoderQu6decodeMFCQBx2io10ByteBufferQmCQCs3net10ConnectionQmZv (warning: (Internal error: pc 0x555
555a69009 in read in psymtab, but not in symtab.)                                  

warning: (Internal error: pc 0x555555a68fa0 in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x555555a69009 in read in psymtab, but not in symtab.)                                                                      

warning: (Internal error: pc 0x555555a69009 in read in psymtab, but not in symtab.)

this=0x7fffec8589c0, warning: (Internal error: pc 0x555555a69009 in read in psymtab, but not in symtab.)

buffer=0x7fffeccd3e40, warning: (Internal error: pc 0x555555a69009 in read in psymtab, but not in symtab.)                                               

session=0x7fffecd36690) at Http1ClientDecoder.d:44                                                                           
44                  throw new IllegalStateException("Client connection is null! The actual type is: "                

The 2nd time:

grpc.GrpcException.GrpcTimeoutException@/home//.dub/packages/grpc-0.3.0-beta.4/grpc/source/grpc/GrpcStream.d(225): Timedout after 5 seconds.
----------------                                                                      
??:? [0x555555d64775]
??:? [0x555555d8c9f6]
??:? [0x555555d7056d]
/home//.dub/packages/grpc-0.3.0-beta.4/grpc/source/grpc/GrpcStream.d:225 [0x55555574a6cb]

Since it's a very simple grpc server, before I investigate further, I want to ask: does this D library's grpc client can talk to a Python grpc server?

The Python side grpc code are generated with:

python -m grpc_tools.protoc -I...

with vesion:

grpcio                             1.31.0    
grpcio-tools                       1.31.0    
protobuf                           3.13.0    

If you know these 2 can work together, can you provide a Python grpc server example? and with the specific Python package version?

Thanks.

Heromyth commented 4 years ago

It seems the handshake failed with Python server. It's so sad that we have not tested this with Python.

mw66 commented 4 years ago

@Heromyth Thanks for the confirmation.

Hi, I created this PR: Python server & client for test with D client & server

https://github.com/huntlabs/grpc-dlang/pull/16

Please try it.

Thanks.

mw66 commented 4 years ago

Test D client with Python server:

$ make pyproto

then test the Python server:

$ cd source
$ python3 server.py
$ python3 client.py  # in another terminal
message: "hi, Hunt"

Now test D client

$ ./client
Heromyth commented 4 years ago

Thanks for your PR. We will test it to find out what happened.

mw66 commented 4 years ago

The other way does not work either:

$ SimpleDemo$ ./server   # D server, can see the request
2020-Nov-25 20:21:23.0448696 | 70846 | trace | GreeterImpl.SayHello | request: Hunt, reply: Hello Hunt | source/GreeterImpl.d:15

$ source$ python3 client.py   # python client in another terminal, but didn't get response.
Heromyth commented 4 years ago

We are testing this. However, nothing has been found.

TimCoraxAudio commented 3 years ago

We are testing this. However, nothing has been found.

Are able to let s know what software you are using. If there are differences, that might highlight an issue. It looks like it could be a mismatched socket interface

Heromyth commented 3 years ago

Here is the example: https://github.com/huntlabs/grpc-dlang/tree/master/examples/SimpleDemo. It's OK for the server and client in D. There are problems for the server in D and the client, or the converse. We are using a tool called Wireshark to monitor the communication, try to find out the difference.

By the way, adding some debug switchers to dub.json, you can get more logs for debug.

    "versions": [
        "HUNT_DEBUG", "HUNT_HTTP_DEBUG", "HUNT_NET_DEBUG"
    ],
mw66 commented 3 years ago

@Heromyth

Do you want to add this issue to GSOC (Google Summer of Code) projects? so someone can try to fix the network issue, and be awarded by Google?

https://github.com/dlang/projects/issues?q=is%3Aissue+is%3Aopen+label%3Agsoc2021

Imperatorn commented 3 years ago

We need to fix this

kubo39 commented 2 years ago

22 and #23 will fix the server side problem.

D grpc client still has some problems, I'll investigate.

Heromyth commented 2 years ago

Thansk. All the patches are merged.

kubo39 commented 2 years ago

The client cannot finish successfully. It seems that the problem is there's no way to stop hunt.net.NetUtil.eventLoop explicitly. Ah, I'm wrong. This uses EventLoopPool internally.

kubo39 commented 2 years ago

Tried,

    // Disconnect.
    channel.destroy();
    import hunt.http.Util;
    CommonUtil.stopScheduler;
    import hunt.net.EventLoopPool;
    shutdownEventLoopPool;

but the client didn't stop.

Heromyth commented 2 years ago

Tried,

    // Disconnect.
    channel.destroy();
    import hunt.http.Util;
    CommonUtil.stopScheduler;
    import hunt.net.EventLoopPool;
    shutdownEventLoopPool;

but the client didn't stop.

You can use gdb to debug this, and check which thread is stopping the client from exit.

mw66 commented 2 years ago

Just an update on the progress (for the new comers): right now Python client can talk to D server, thanks @kubo39 ; but the other way still does not work. People can give the demo a try:

https://github.com/huntlabs/grpc-dlang/tree/master/examples/SimpleDemo

Since D's strength is on the server side, I'd say 60% of the bug fixed :-)