Skip to content

Updating Uvicorn to 0.14.0 to increase ws max_size to > 1mb causes a cascade of errors #389

@turukawa

Description

@turukawa

Updated and cross-referenced from tiangolo/uvicorn-gunicorn-docker#74

I needed to update Uvicorn to 0.14.0 since this version permits websockets to send > 1mb of data in a message. I update in Poetry. When I restart the Docker image, I get the following error scrolling off indefinitely:

backend_1 | error walking file system: FileNotFoundError [Errno 2] No such file or directory: '/app/.venv/bin/python'

These articles give me some indication it has something to do with Uvicorn and reload:

I created a custom version of /start-reload.sh with the following to reload the app directory only:

LOG_LEVEL=${LOG_LEVEL:-critical}
APP_DIRECTORY=${APP_DIRECTORY:-./app/app}
WS=${WS:-auto}
WS_MAX=${WS_MAX:-15728640}
exec uvicorn --reload --reload-dir $APP_DIRECTORY --host $HOST --port $PORT --ws $WS --ws-max-size $WS_MAX "$APP_MODULE"

This makes no difference at all, and I'd appreciate any help, both with the data send limit, and this never-ending .venv not found error.

Thanks.

Here's the stack trace, bracketed by never-ending FileNotFoundErrors:

backend_1 | error walking file system: FileNotFoundError [Errno 2] No such file or directory: '/app/.venv/bin/python'
backend_1 | ERROR: Exception in ASGI application
backend_1 | Traceback (most recent call last):
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 750, in transfer_data
backend_1 | message = await self.read_message()
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 874, in read_message
backend_1 | frame = await self.read_data_frame(max_size=max_size)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 895, in read_data_frame
backend_1 | frame = await self.read_frame(max_size)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 971, in read_frame
backend_1 | frame = await Frame.read(
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/websockets/legacy/framing.py", line 80, in read
backend_1 | raise PayloadTooBig(f"over size limit ({length} > {max_size} bytes)")
backend_1 | websockets.exceptions.PayloadTooBig: over size limit (106508 > 24869 bytes)
backend_1 |
backend_1 | The above exception was the direct cause of the following exception:
backend_1 |
backend_1 | Traceback (most recent call last):
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 171, in run_asgi
backend_1 | result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 59, in __call__
backend_1 | return await self.app(scope, receive, send)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/fastapi/applications.py", line 199, in __call__
backend_1 | await super().__call__(scope, receive, send)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/starlette/applications.py", line 111, in __call__
backend_1 | await self.middleware_stack(scope, receive, send)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/starlette/middleware/errors.py", line 146, in __call__
backend_1 | await self.app(scope, receive, send)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/starlette/middleware/cors.py", line 70, in __call__
backend_1 | await self.app(scope, receive, send)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/starlette/exceptions.py", line 58, in __call__
backend_1 | await self.app(scope, receive, send)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/starlette/routing.py", line 566, in __call__
backend_1 | await route.handle(scope, receive, send)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/starlette/routing.py", line 283, in handle
backend_1 | await self.app(scope, receive, send)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/starlette/routing.py", line 57, in app
backend_1 | await func(session)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/fastapi/routing.py", line 247, in app
backend_1 | await dependant.call(**values)
backend_1 | File "/app/./app/api/api_v1/endpoints/epub.py", line 52, in websocket_endpoint2
backend_1 | await websocket.send_json(response)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/starlette/websockets.py", line 137, in send_json
backend_1 | await self.send({"type": "websocket.send", "text": text})
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/starlette/websockets.py", line 68, in send
backend_1 | await self._send(message)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 232, in asgi_send
backend_1 | await self.send(data)
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 471, in send
backend_1 | await self.ensure_open()
backend_1 | File "/opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 735, in ensure_open
backend_1 | raise self.connection_closed_exc()
backend_1 | websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason
backend_1 | /opt/pyenv/versions/3.9.5/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py:180: RuntimeWarning: coroutine 'WebSocket.receive_json' was never awaited
backend_1 | self.transport.close()
backend_1 | RuntimeWarning: Enable tracemalloc to get the object allocation traceback
backend_1 | error walking file system: FileNotFoundError [Errno 2] No such file or directory: '/app/.venv/bin/python'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions