AttributeError: 'grpc._cython.cygrpc._ServicerContext' object has no attribute 'add_done_callback'

ยอดดู 143 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

Tarek Saad

ยังไม่อ่าน,
3 เม.ย. 2564 17:56:563/4/64
ถึง grpc.io
Hi,

Using python grpc.aio, I'm not able to add a callback  on server side (using context) to be invoked on a grpc stream terminated/cancelled -- I use grpc.aio.server().
The documentation here mentions the callback, but I can't seem to be able to get it to work. 

If I use grpc.server() instead, I can set add_callback()

I'm using:
Name: grpcio
Version: 1.36.1
Name: grpcio-tools
Version: 1.35.0
Name: aiogrpc
Version: 1.8

Thanks


Lidi Zheng

ยังไม่อ่าน,
5 เม.ย. 2564 14:24:195/4/64
ถึง grpc.io
Hi,

`add_done_callback` wasn't added to grpc.aio.Server because there was a discussion that it overlaps with server interceptors: https://github.com/grpc/grpc/pull/22503.

I can update the PR later this week. If possible, please explain more about your use case and why you think `add_done_callback` would be handy.

Tarek Saad

ยังไม่อ่าน,
5 เม.ย. 2564 16:52:485/4/64
ถึง grpc.io
Hi Lidi,

Thanks for getting back. My application is for a long-lived bidirectional stream.
On the server, I need to detect a client disconnected. I understand multiple streams are multiplexed on same connection. However, in my case it is a long-lived bidirectional stream and the stream will terminate only when the client has died. 
When stream is terminated, and if the client/stream does not reconnect to server within a timeout, the server will need to purge out state associated with the client.

I'm counting on "add_done_callback" being able to register a callback that gets invoked before the stream is terminated. This allows me to start the timer on server side to wait before purging state associated with the client/stream.
I was also suggested to look into enabling TCP keepalives - but I have not seen a way for the application to be notified if/when TCP connection is terminated.

If you have better ideas, I much appreciate it.
BTW, I quickly sifted through the PR, there is a suggestion to catch asyncio.CancelledError.. However, 1) I am not sure if asyncio.CancelledError is raised if client disconnects, and 2) whether  application/server will have a chance to do anything about it before underlying aio thread get cleaned up?

async def handler(request, service_context):
    try:
        make_something(...)
    except asyncio.CancelledError:
        clean_stuff_related_to_current_RPC(....)

Regards,
Tarek

Sunandan Nandi

ยังไม่อ่าน,
6 เม.ย. 2564 14:46:186/4/64
ถึง grpc.io
Hi Tarek,

As you are using bidi stream then you must be writing to client, now assume your client is killed. At this moment if you try to write something from server you will get an exception and that way you can detect your client dead.

This is the easiest way to detect dead client. 

Regards,
SN

Jeff Steger

ยังไม่อ่าน,
10 เม.ย. 2564 20:46:1710/4/64
ถึง grpc.io


Hi all,
I am using grpc 1.23.0. I recently came across an issue that seems to be documented here:

In sum:

When a new call is created with a streaming request/non-streaming response, an initial message is sent immediately (before call.write() is ever explicitly invoked) with a blank value.



Has anyone seen this before and does anyone know if there is a grpc version where this is fixed?  Thanks!

Sunandan Nandi

ยังไม่อ่าน,
12 เม.ย. 2564 12:36:0612/4/64
ถึง Jeff Steger, grpc.io
Hi,
Sounds strange. I have recently used a similar RPC call with grpc 1.34.
Not observed such issue. 
You can try 1.34 or the latest.

Regards,
Nandi

--
You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/_0wBUQB_QDk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CAA-WHum4DOYr9jQAX-iDSxc%3Dy9F4mFMYWPq72kWyRuiUpbDM5Q%40mail.gmail.com.

Lidi Zheng

ยังไม่อ่าน,
14 เม.ย. 2564 14:49:0214/4/64
ถึง grpc.io
Hi Tarek,

The `asyncio.CancelledError` is only generated when an asyncio coroutine is cancelled, in gRPC case, an ongoing RPC is cancelled locally. If the RPC representation (the grpc.aio.Call object) is passed to other coroutines, it's possible that they might cancel it, hence current coroutine will receive a `asyncio.CancelledError`.

Jeff Steger

ยังไม่อ่าน,
15 เม.ย. 2564 13:12:1015/4/64
ถึง Lidi Zheng, grpc.io
Lidi,
Your response was not to my question, but probably to someone else’s question. 

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 view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/31788ed7-0e23-4b39-b88a-6b7e81eb72e5n%40googlegroups.com.

Lidi Zheng

ยังไม่อ่าน,
15 เม.ย. 2564 13:17:5915/4/64
ถึง Jeff Steger, grpc.io
Oops sorry, it seems two threads got tangled in Google Group: https://groups.google.com/g/grpc-io/c/_0wBUQB_QDk/m/GxHoowm-CQAJ
ตอบทุกคน
ตอบกลับผู้สร้าง
ส่งต่อ
ข้อความใหม่ 0 รายการ