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

/gradio_api/heartbeat/<<sess_id>> fails in browser (http code 500) #10215

Open
1 task done
ErnstDinkelmann opened this issue Dec 17, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@ErnstDinkelmann
Copy link

ErnstDinkelmann commented Dec 17, 2024

Describe the bug

Hi there

Asked in discord, but no response thus far. Not sure it's a bug or our configs.

Issue:
All assets (e.g. css, js, docs) are successfully received in brower (inspect > network), except the heartbeat (which is pending and then returns 500 after some time).
Only happens when a gr.State variable is present.
So the minimal repro only has a gr.State and still the problem happens.

Basic setup:
NGINX reverse proxy. Tried to implement according to deployment guide.
proxy_cookie_flags ~ secure httponly samesite=lax; Have tested without this, makes no difference.
proxy_set_header X-Forwarded-Proto $scheme; Have tested without this, makes no difference.
proxy_set_header X-Forwarded-Host $host; When including this, nothing works. Even using $http_host, nothing works. So not using this header at all. "Connection Errored out" on UI.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import gradio as gr
from fastapi import FastAPI
import uvicorn

app = FastAPI(debug=True)

with gr.Blocks(analytics_enabled=False) as gr_block_app: 
    a_state = gr.State(None)

gr_block_app.queue()

app = gr.mount_gradio_app(
    app, 
    blocks=gr_block_app, 
    path='/app',
)

uvicorn.run(app, port=8080, host='0.0.0.0')

NGINX
...
http {
        ...
        sendfile on;
        tcp_nopush on;
        keepalive_timeout 75;
        types_hash_max_size 2048;
        server_tokens off;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        proxy_read_timeout 600s;
        proxy_cookie_flags ~ secure httponly samesite=lax;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
        gzip off;
        large_client_header_buffers 6 64k;

        upstream app_server {
                keepalive 60;
                server 127.0.0.1:8080 fail_timeout=0;
        }

        server {
                listen 443 ssl so_keepalive=on;

                include snippets/self-signed.conf;
                include snippets/ssl-params.conf;

                server_name my_server_domain;

                if ($request_method !~ ^(GET|HEAD|POST)$) {
                        return 444;
                }

                # just removing /answers prefix on URL as that's how request arrives from downstream
                rewrite ^/answers(.*)$ /$1 last;

                location / {
                        proxy_pass http://app_server;
                        proxy_buffering off;
                        proxy_redirect off;
                        proxy_http_version 1.1;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection "upgrade";
                        proxy_set_header Host $host;
                        # proxy_set_header X-Forwarded-Host $host;  #cannot use: "Connection Errorred out"
                        proxy_set_header X-Forwarded-Proto $scheme;
                        proxy_hide_header Access-Control-Allow-Origin;
                        proxy_connect_timeout 60s;
                        proxy_send_timeout 60s;
                        proxy_read_timeout 60s;
                }
        }
}

Screenshot

image

Logs

App log:
Dec 17 09:41:27 ... "GET /app/gradio_api/heartbeat/2pu0j9q9bc9 HTTP/1.1" 200 OK
So it seems the heartbeat is successfully done by the app.

NGINX Access log:
[17/Dec/2024:09:42:31 +0200] "GET /answersapp/gradio_api/heartbeat/2pu0j9q9bc9 HTTP/1.1" 200 54 "https://my_server_domain/app/" "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36"

There's nothing in the NGINX error log, only the above line in the Access log. I do notice the URL seems invalid here, should be /answers/app/gradio_api/heartbeat/2pu0j9q9bc9 or /app/gradio_api/heartbeat/2pu0j9q9bc9 depending on whether it's before the URL rewrite or after.

System Info

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 5.8.0
gradio_client version: 1.5.1

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

aiofiles: 23.2.1
anyio: 4.7.0
audioop-lts is not installed.
fastapi: 0.115.6
ffmpy: 0.4.0
gradio-client==1.5.1 is not installed.
httpx: 0.28.1
huggingface-hub: 0.26.5
jinja2: 3.1.4
markupsafe: 2.1.5
numpy: 2.2.0
orjson: 3.10.12
packaging: 24.2
pandas: 2.2.3
pillow: 11.0.0
pydantic: 2.10.3
pydub: 0.25.1
python-multipart: 0.0.19
pyyaml: 6.0.2
ruff: 0.8.2
safehttpx: 0.1.6
semantic-version: 2.10.0
starlette: 0.41.3
tomlkit: 0.13.2
typer: 0.15.1
typing-extensions: 4.12.2
urllib3: 2.2.3
uvicorn: 0.32.1
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2024.10.0
httpx: 0.28.1
huggingface-hub: 0.26.5
packaging: 24.2
typing-extensions: 4.12.2
websockets: 14.1

Severity

I can work around it

@ErnstDinkelmann ErnstDinkelmann added the bug Something isn't working label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant