what is _MultiThreadedRendezvous in grpc and how to parse it
Asked Answered
I

3

9

I'm trying to send a grpc request and I'm expected to receive stream of message back. Instead I'm receiving a response as <_MultiThreadedRendezvous object>. Can anyone help me to understand why I'm receiving this and what should I do to extract the expected message from this object. The server is C++ and client is python in this case.

Irmgard answered 14/8, 2020 at 12:55 Comment(0)
L
11

Please take a look at gRPC's example of streaming RPC. The _MultiThreadedRendezvous object is the library's representation of an RPC result. It is an iterable, you can use for to fetch all responses, or you can use list() to get all messages.

Luckin answered 19/8, 2020 at 18:31 Comment(4)
What you shared is really helpful. But sometime I receive no messages from that iterator sometimes I do. Have you experienced that. @lidiIrmgard
There are many possibility that could lead to that behavior. Generally, client should receive all the messages sent by peer. If you believe it is a bug in gRPC library, please create a reproduction case and submit an issue to github.com/grpc/grpc/issues.Luckin
No worries. I don't think it is due to grpc library. Something wrong on my side of code.Irmgard
loop it through the for loop solved this, thanks.Fleabag
A
3

Using e.code() and e.details() helped me parsing it:

try:
    response = stub.SayHello(...)
except _MultiThreadedRendezvous as e:
    if e.code() == grpc.StatusCode.CANCELLED:
        pass 
        # process cancelled status

    elif e.code() == grpc.StatusCode.UNAVAILABLE and 'Connection reset by peer' in e.details():
        pass 
        # process unavailable status

    else:
        raise

Looking at the source code of that error helped me understand how to parse it.

Credit to this answer on another question.

Adlare answered 15/12, 2021 at 16:11 Comment(0)
F
0

I've spent few hours on the same issue and i've figured out that _MultiThreadedRendezvous returned could be because of some issue has occurred. This is not the normal behavior of grpc.

For my case, i've NOT kept the .proto file up to date for both of my services.

I'm setting up a microservices with 2 services: grpc-service and bff-service. Both services have the same .proto file because they need to contact to each other.

But i've changed the .proto file of grpc-service, but not update in bff-serivce, which led to this issue. I've updated it to be the same as each other, and it's worked.

Hope this information helped someone.

Fleabag answered 29/9, 2023 at 2:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.