fix(sse): flush stream headers eagerly so clients connect instantly#1295
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/streamresolves — andfetch()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 toHeartbeatInterval(15s) away. With no traffic andEvents this session: 0, the browser sat pending the whole interval.How
Write a no-op
:connectedSSE comment and flush immediately afterConnect(), so the headers go out at once and the client connects instantly. Two lines.Notes
src/BuildingBlocks/Web/Sse(protected) — change is minimal and self-contained.Webproject builds clean (0 warnings).🤖 Generated with Claude Code