python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

Encoding errors while sending aren't thrown because the sending task is started as fire and forget

Open SoerenBusse opened this issue 5 years ago • 1 comments

Hey there,

I've incorrectly passed a string instead of a message to a grpc field. This will result in an exception which is thrown during encoding in the __bytes__ method (https://github.com/danielgtaylor/python-betterproto/blob/master/src/betterproto/init.py#L634). This method throws an exception that it cannot encode a string as a message.

However the user never sees the exception, because the sending task is started as fire and forget, without handling the exception case. This will result in hidden exceptions. The user only notices that the program doesn't work as expected or it feels like the program has hung up:

sending_task = asyncio.ensure_future(
    self._send_messages(stream, request_iterator)
)

https://github.com/danielgtaylor/python-betterproto/blob/master/src/betterproto/grpc/grpclib_client.py#L153

SoerenBusse avatar Dec 21 '20 18:12 SoerenBusse

That's not ideal! thanks for reporting it.

nat-n avatar Dec 21 '20 19:12 nat-n