nats.py
nats.py copied to clipboard
Add max_message_size as a configurable connection parameter
The WebSocket library used has a default max message size of 4MB (per https://docs.aiohttp.org/en/v3.8.4/client_reference.html#aiohttp.ClientSession.ws_connect).
If the NATS server supports and has messages larger than this 4MB limit, we encounter the following error during reading of the message:
nats: encountered error
Traceback (most recent call last):
File "/home/seb/.local/lib/python3.8/site-packages/nats/aio/client.py", line 2073, in _read_loop
await self._ps.parse(b)
File "/home/seb/.local/lib/python3.8/site-packages/nats/protocol/parser.py", line 95, in parse
self.buf.extend(data)
TypeError: can't extend bytearray with NoneType
This error basically translates to, self.buf
is smaller than the size of the payload b
(within the AIO WebSocketReader
class).
As such, I've added a new max_message_size
property to the connection, which is passed to the WebSocket transport to resolve this issue. I maintained the default 4MB limit.