dapr / python-sdk

Dapr SDK for Python
Apache License 2.0
222 stars 125 forks source link

[BUG] Asyncio DaprClient raising "coroutine 'Channel.close' was never awaited" #642

Closed ivarec closed 9 months ago

ivarec commented 9 months ago

Expected Behavior

I'm getting this error in my logs when an asyncio DaprClient exists an async with block:

./dapr/aio/clients/grpc/client.py:172: RuntimeWarning: coroutine 'Channel.close' was never awaited

I haven't perceived any other side effects, but I haven't tested much. Maybe there is a resource leak.

Dapr version: 1.12.0 SDK version: 1.12.0 Python version: 3.9

Actual Behavior

To have DaprClient correctly manage the lifecycle of the channel and close it upon exiting the async with block.

Steps to Reproduce the Problem

Just create an asyncio DaprClient and use it in an async with block.

Also, I've noticed that the bug appears to be caused by this method on ./dapr/aio/clients/grpc/client.py, line 172:

    async def close(self):
        """Closes Dapr runtime gRPC channel."""
        if hasattr(self, '_channel') and self._channel:
            self._channel.close()

There seems to be a missing await on self._channel.close().

Release Note

RELEASE NOTE:

berndverst commented 9 months ago

I'll patch this up and will add a 1.12.1. I won't bother with updates for 1.11.X and earlier however. The SDK can be used with previous versions of Dapr Runtime, so no concerns there.

berndverst commented 9 months ago

Fixed in 1.12.1

https://github.com/dapr/python-sdk/releases/tag/v1.12.1

Should be available via PyPI in a few minutes. Build job here: https://github.com/dapr/python-sdk/actions/runs/7008586040