responder icon indicating copy to clipboard operation
responder copied to clipboard

Hitting limit of 1 MB for websocket read

Open roshammar opened this issue 6 years ago • 0 comments

I have a websocket route in responder, which reads data uploaded from a browser. It works great, until a file larger than 1 MB is uploaded. Then a starlette.websockets.WebSocketDisconnect: 1006 is raised.

This is my code

@api.route('/ws')
async def websocket(ws, websocket=True):
    await ws.accept()

    # Wait for actual file as bytes
    file_data = await ws.receive_bytes()

This is the stack trace

/usr/local/lib/python3.7/site-packages/responder/api.py:256: RuntimeWarning: coroutine 'BackgroundQueue.__call__' was never awaited
  error=True
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
ERROR: Exception in ASGI application
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 147, in run_asgi
    result = await asgi(self.asgi_receive, self.asgi_send)
  File "/usr/local/lib/python3.7/site-packages/responder/api.py", line 229, in asgi
    await self._dispatch_ws(ws)
  File "/usr/local/lib/python3.7/site-packages/responder/api.py", line 249, in _dispatch_ws
    await r
  File "/usr/local/lib/python3.7/site-packages/responder/background.py", line 42, in __call__
    return await asyncio.ensure_future(func(*args, **kwargs))
  File "api.py", line 81, in websocket
    file_data = await ws.receive_bytes()
  File "/usr/local/lib/python3.7/site-packages/starlette/websockets.py", line 91, in receive_bytes
    self._raise_on_disconnect(message)
  File "/usr/local/lib/python3.7/site-packages/starlette/websockets.py", line 80, in _raise_on_disconnect
    raise WebSocketDisconnect(message["code"])
starlette.websockets.WebSocketDisconnect: 1006

So, I see that uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol is inheriting from websockets.WebSocketServerProtocol, and that takes an argument max_size that happens to default to 2 ** 20, but I am not quite sure how to change that from responder.

Any suggestions would be highly appreciated!

roshammar avatar Feb 14 '19 11:02 roshammar