[PR #15] [MERGED] fix: read-idle timeout on SSE so a stalled stream can't hang events() #25

Closed
opened 2026-10-31 22:03:55 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Comfy-Org/comfy-typescript-sdk/pull/15
Author: @wei-hai
Created: 7/22/2026
Status: ✅ Merged
Merged: 7/22/2026
Merged by: @wei-hai

Base: main ← Head: fix/sse-idle-timeout


📝 Commits (1)

  • 6f2e83a fix: read-idle timeout on SSE so a stalled stream can't hang events()

📊 Changes

2 files changed (+61 additions, -1 deletions)

View changed files

📝 src/low/sse.test.ts (+22 -0)
📝 src/low/sse.ts (+39 -1)

📄 Description

Found running a real >10-minute job against prod: the SSE stream went silent at ~3 min (no frames, no keepalive, no close — a "zombie" connection), and job.events() hung — still blocked minutes after the job had already completed. poll/wait/run were unaffected (the job itself finished fine).

Root cause

iterateSse read the fetch body with no idle timeout, so it blocks forever on a stalled-but-open connection. The high-level Job.events() reconnect/poll-fallback only runs when the stream ends (the async iterator returns or throws), which never happens for a zombie → events() hangs.

Fix

Add a byte-level read-idle timeout to iterateSse (default SSE_IDLE_TIMEOUT_MS, well above the server keepalive interval). It resets on any bytes — so keepalive comments (which eventsource-parser drops as non-messages) still count as liveness, and only a truly silent connection trips it. A stalled stream now errors, which Job.events() already catches and turns into a poll (terminal?) / reconnect.

Tests

Added a regression test: a stream that emits two frames then holds open + silent → iterateSse errors quickly (~idle timeout) instead of hanging, after delivering the pre-stall frames. Full suite green; tsc/oxfmt/hygiene clean.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Comfy-Org/comfy-typescript-sdk/pull/15 **Author:** [@wei-hai](https://github.com/wei-hai) **Created:** 7/22/2026 **Status:** ✅ Merged **Merged:** 7/22/2026 **Merged by:** [@wei-hai](https://github.com/wei-hai) **Base:** `main` ← **Head:** `fix/sse-idle-timeout` --- ### 📝 Commits (1) - [`6f2e83a`](https://github.com/Comfy-Org/comfy-typescript-sdk/commit/6f2e83a4a4b1f88f6625cdd73476df0fa1d94b7b) fix: read-idle timeout on SSE so a stalled stream can't hang events() ### 📊 Changes **2 files changed** (+61 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/low/sse.test.ts` (+22 -0) 📝 `src/low/sse.ts` (+39 -1) </details> ### 📄 Description Found running a real >10-minute job against prod: the SSE stream went silent at ~3 min (no frames, no keepalive, no close — a "zombie" connection), and `job.events()` **hung** — still blocked minutes after the job had already completed. `poll`/`wait`/`run` were unaffected (the job itself finished fine). ## Root cause `iterateSse` read the fetch body with no idle timeout, so it blocks forever on a stalled-but-open connection. The high-level `Job.events()` reconnect/poll-fallback only runs when the stream **ends** (the async iterator returns or throws), which never happens for a zombie → `events()` hangs. ## Fix Add a **byte-level** read-idle timeout to `iterateSse` (default `SSE_IDLE_TIMEOUT_MS`, well above the server keepalive interval). It resets on **any bytes** — so keepalive comments (which `eventsource-parser` drops as non-messages) still count as liveness, and only a truly silent connection trips it. A stalled stream now errors, which `Job.events()` **already catches** and turns into a poll (terminal?) / reconnect. ## Tests Added a regression test: a stream that emits two frames then holds open + silent → `iterateSse` errors quickly (~idle timeout) instead of hanging, after delivering the pre-stall frames. Full suite green; tsc/oxfmt/hygiene clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 22:03:55 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Comfy-Org/comfy-typescript-sdk#25
No description provided.