Skip to content

Blocks unload event delayed significantly (~30 min) in Kubernetes environment, resolved by lowering heartbeat interval #13347

Description

@johnsbucket

Describe the bug

In a Kubernetes (k8s) environment, the unload event of Gradio Blocks is triggered with a long delay (e.g., ~30 minutes) after the client disconnects or the interface is closed. This occurs consistently with the latest versions of Gradio 4, 5, and 6. The issue does not appear when running the same application locally (outside k8s).

Temporarily, setting the heartbeat_interval to a smaller value (e.g., 1 second) resolves the problem – the unload event then fires as expected within a short time.

Code:

from datetime import datetime

import gradio as gr


def on_load():
    print(f"load: {datetime.now()}")


def on_unload():
    print(f"unload: {datetime.now()}")


with gr.Blocks() as demo:
    demo.load(on_load)
    demo.unload(on_unload)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=9527)

Output (the browser tab is closed immediately after the page is loaded):

load: 2026-04-30 15:10:20.650028
unload: 2026-04-30 15:26:35.641765

Setting GRADIO_IS_E2E_TEST environment variable to change heartbeat interval from 15s to 0.25s can fix this problem. Setting heartbeat interval to 1s can also resolve the issue.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

from datetime import datetime

import gradio as gr


def on_load():
    print(f"load: {datetime.now()}")


def on_unload():
    print(f"unload: {datetime.now()}")


with gr.Blocks() as demo:
    demo.load(on_load)
    demo.unload(on_unload)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=9527)

Screenshot

No response

Logs

System Info

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 5.49.1
gradio_client version: 1.13.3

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

aiofiles: 24.1.0
anyio: 4.13.0
audioop-lts is not installed.
brotli: 1.2.0
fastapi: 0.136.1
ffmpy: 1.0.0
gradio-client: 1.13.3
groovy: 0.1.2
httpx: 0.28.1
huggingface-hub: 1.11.0
jinja2: 3.1.6
markupsafe: 3.0.3
numpy: 2.4.4
orjson: 3.11.8
packaging: 26.1
pandas: 2.3.3
pillow: 11.3.0
pydantic: 2.11.10
pydub: 0.25.1
python-multipart: 0.0.26
pyyaml: 6.0.3
ruff: 0.15.11
safehttpx: 0.1.7
semantic-version: 2.10.0
starlette: 0.52.1
tomlkit: 0.13.3
typer: 0.24.2
typing-extensions: 4.15.0
uvicorn: 0.46.0
mcp is not installed.
pydantic: 2.11.10
authlib is not installed.
itsdangerous is not installed.


gradio_client dependencies in your environment:

fsspec: 2026.3.0
httpx: 0.28.1
huggingface-hub: 1.11.0
packaging: 26.1
typing-extensions: 4.15.0
websockets: 15.0.1

Severity

Blocking usage of gradio

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtoclosefeatures that we will most likely not implement (low priority or users can implement themselves)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions