gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
34.22k stars 2.6k forks source link

Gradio5 SSR - RuntimeError: Response content longer than Content-Length #9537

Open yoonniverse opened 1 month ago

yoonniverse commented 1 month ago

Describe the bug

I installed gradio 5 preview to test ssr feature, but encountered "RuntimeError: Response content longer than Content-Length".

Have you searched existing issues? πŸ”Ž

Reproduction

pip install gradio --pre
# test.py
import gradio as gr

with gr.Blocks() as demo:
    gr.Dropdown(["apple", "banana"])

demo.launch(ssr_mode=True)
GRADIO_SERVER_NAME=0.0.0.0 python test.py

It runs fine when I set ssr_mode=False.

Screenshot

image

Logs

ERROR:    Exception in ASGI application
  + Exception Group Traceback (most recent call last):
  |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/_utils.py", line 77, in collapse_excgroups
  |     yield
  |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/base.py", line 186, in __call__
  |     async with anyio.create_task_group() as task_group:
  |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 736, in __aexit__
  |     raise BaseExceptionGroup(
  | exceptiongroup.ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi
    |     result = await app(  # type: ignore[func-returns-value]
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    |     return await self.app(scope, receive, send)
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
    |     await super().__call__(scope, receive, send)
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/applications.py", line 113, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/errors.py", line 187, in __call__
    |     raise exc
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/errors.py", line 165, in __call__
    |     await self.app(scope, receive, _send)
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/base.py", line 185, in __call__
    |     with collapse_excgroups():
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/contextlib.py", line 153, in __exit__
    |     self.gen.throw(typ, value, traceback)
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/_utils.py", line 83, in collapse_excgroups
    |     raise exc
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/base.py", line 188, in __call__
    |     await response(scope, wrapped_receive, send)
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/responses.py", line 153, in __call__
    |     await send({"type": prefix + "http.response.body", "body": self.body})
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in _send
    |     await send(message)
    |   File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 528, in send
    |     raise RuntimeError("Response content longer than Content-Length")
    | RuntimeError: Response content longer than Content-Length
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/base.py", line 185, in __call__
    with collapse_excgroups():
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/_utils.py", line 83, in collapse_excgroups
    raise exc
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/base.py", line 188, in __call__
    await response(scope, wrapped_receive, send)
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/responses.py", line 153, in __call__
    await send({"type": prefix + "http.response.body", "body": self.body})
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in _send
    await send(message)
  File "/home/ubuntu/miniconda3/envs/gradio5/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 528, in send
    raise RuntimeError("Response content longer than Content-Length")
RuntimeError: Response content longer than Content-Length

System Info

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 5.0.0b5
gradio_client version: 1.4.0b2

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
anyio: 4.6.0
fastapi: 0.115.0
ffmpy: 0.4.0
gradio-client==1.4.0-beta.2 is not installed.
httpx: 0.27.2
huggingface-hub: 0.25.1
jinja2: 3.1.4
markupsafe: 2.1.5
numpy: 2.1.1
orjson: 3.10.7
packaging: 24.1
pandas: 2.2.3
pillow: 10.4.0
pydantic: 2.9.2
pydub: 0.25.1
python-multipart: 0.0.12
pyyaml: 6.0.2
ruff: 0.6.9
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.12.5
typing-extensions: 4.12.2
urllib3: 2.2.3
uvicorn: 0.31.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2024.6.1
httpx: 0.27.2
huggingface-hub: 0.25.1
packaging: 24.1
typing-extensions: 4.12.2
websockets: 12.0

Severity

I can work around it

abidlabs commented 1 month ago

Hi @yoonniverse can you try again with the latest beta release we just released? It should be version 5.0.0b6

yoonniverse commented 1 month ago

Thanks for the review, but I still have the same issue after upgrading to 5.0.0b6 too.

abidlabs commented 1 month ago

Thanks for checking, can you please share with us more information about your environment, specifically:

And you are on Linux, right?

yoonniverse commented 1 month ago
jmetzen commented 1 month ago

I am getting a very similar error with gradio 5.0.1:

... File "/.venv/lib/python3.11/site-packages/h11/_connection.py", line 545, in send_with_data_passthrough writer(event, data_list.append) File "/.venv/lib/python3.11/site-packages/h11/_writers.py", line 65, in call self.send_data(event.data, write) File "/.venv/lib/python3.11/site-packages/h11/_writers.py", line 91, in send_data raise LocalProtocolError("Too much data for declared Content-Length") h11._util.LocalProtocolError: Too much data for declared Content-Length

Any workarounds?

ngaudemet commented 1 month ago

I have the same issue with gradio==5.1

python3.11/site-packages/h11/_writers.py", line 91, in send_data raise LocalProtocolError("Too much data for declared Content-Length") h11._util.LocalProtocolError: Too much data for declared Content-Length

Ethan-yt commented 1 month ago

same here

Ethan-yt commented 1 month ago

browser: chrome / safari Python: 3.12 Node: v22.10.0 gradio: 5.3.0

macos

jmetzen commented 3 days ago

I am still getting this error. Any idea how it can be resolved @abidlabs ?