diff --git a/.changeset/whole-bears-rescue.md b/.changeset/whole-bears-rescue.md new file mode 100644 index 0000000000..7f0585df45 --- /dev/null +++ b/.changeset/whole-bears-rescue.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +fix:Send more than one heartbeat message diff --git a/gradio/routes.py b/gradio/routes.py index d87007c1c8..d0598de2e1 100644 --- a/gradio/routes.py +++ b/gradio/routes.py @@ -642,7 +642,10 @@ class App(FastAPI): await asyncio.sleep(check_rate) if time.perf_counter() - last_heartbeat > heartbeat_rate: message = {"msg": "heartbeat"} - last_heartbeat = time.time() + # Need to reset last_heartbeat with perf_counter + # otherwise only a single hearbeat msg will be sent + # and then the stream will retry leading to infinite queue 😬 + last_heartbeat = time.perf_counter() if message: yield f"data: {json.dumps(message)}\n\n"