Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max_message_size as a configurable connection parameter #470

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sebastian-king
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant