danielgtaylor / python-betterproto

Clean, modern, Python 3.6+ code generator & library for Protobuf 3 and async gRPC
MIT License
1.45k stars 196 forks source link

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

Open SoerenBusse opened 3 years ago

SoerenBusse commented 3 years ago

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

nat-n commented 3 years ago

That's not ideal! thanks for reporting it.