vmagamedov / grpclib

Pure-Python gRPC implementation for asyncio
http://grpclib.readthedocs.io
BSD 3-Clause "New" or "Revised" License
936 stars 92 forks source link

wait_closed not working consistently #107

Open twavv opened 4 years ago

twavv commented 4 years ago

I'm not entirely sure what this issue is.

Basically, I have a server.

async def start_server():
    await server.start(...)
    await server.wait_closed()
    print("Closed the server")

elsewhere, I have a function that's triggered when the app has requested a shutdown.

async def shutdown_server():
    server.close()
    await server.wait_closed()
    print("shutdown_server complete")

For some reason, the await server.wait_closed() in start_server never completes, but it does in shutdown_server.

I was able to "fix" this locally by just doing the await server.wait_closed() in a loop with a timeout. Not sure what a minimal reproduction would be. For me, it seems to happen after I've done any gRPC request (it works fine if the shutdown happens before any requests are received, but if the server has handled even unary/unary requests, it doesn't...).

vmagamedov commented 4 years ago

This is a known issue, it is related to https://github.com/python-hyper/hyper-h2/issues/1181.

Currently grpclib cancels all current requests and waits until they finish. But when new requests come this don't works as expected.

What should be done: grpclib should send GOAWAY frame and complete all current requests. GOAWAY makes it possible to stop new requests coming. But currently sending GOAWAY frame is almost equal to immediately closing an entire connection.