Skip to content

fix(sse): flush stream headers eagerly so clients connect instantly#1295

Merged
iammukeshm merged 1 commit into
mainfrom
fix/sse-eager-header-flush
Jun 9, 2026
Merged

fix(sse): flush stream headers eagerly so clients connect instantly#1295
iammukeshm merged 1 commit into
mainfrom
fix/sse-eager-header-flush

Conversation

@iammukeshm

Copy link
Copy Markdown
Member

What

On the dashboard, the Overview "System status" card sat on Connecting ("Waiting for the stream to come online") for up to 15 seconds after every connect/reconnect on an idle stream.

Why

The client flips to Connected only when its fetch() to /api/v1/sse/stream resolves — and fetch() on a streaming response resolves when the response headers arrive. The server handler (SseEndpoints.cs) set the headers and then entered the read loop without writing anything, so Kestrel buffered the headers until the first body write — which was the heartbeat, up to HeartbeatInterval (15s) away. With no traffic and Events this session: 0, the browser sat pending the whole interval.

How

Write a no-op :connected SSE comment and flush immediately after Connect(), so the headers go out at once and the client connects instantly. Two lines.

Notes

  • Touches src/BuildingBlocks/Web/Sse (protected) — change is minimal and self-contained.
  • No test asserts the SSE stream bytes, so the extra leading comment is safe; the Web project builds clean (0 warnings).
  • Changelog entry added in the docs repo.

🤖 Generated with Claude Code

The SSE stream handler set the response headers and then entered the read
loop without writing anything, so Kestrel buffered the headers until the
first body write - which was the heartbeat up to 15s away. The browser's
fetch() resolves on response headers, so the dashboard sat on "connecting"
for up to 15s on every connect/reconnect with an idle stream.

Write a no-op ":connected" SSE comment and flush immediately after Connect()
so the headers go out at once and the client flips to "connected" right away.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@iammukeshm iammukeshm merged commit dcbb922 into main Jun 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant