Repository navigation
fix(web): bound SSE writes so a stalled client cannot block the run - #487
Merged
Merged
Conversation
Joe broadcasts synchronously: Session.Publish writes to every subscriber before it returns, so a client that stops reading its SSE stream blocks BroadcastLogger.Print and with it the whole run. Set a per-write deadline in handleEvents so a stalled subscriber fails its own connection instead; the deadline is refreshed on every write, so an active client is never disconnected, and EventSource reconnects with Last-Event-ID to replay. Co-Authored-By: Agent-Yan <352840372+Agent-Yan@users.noreply.github.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.
Summary
The dashboard streams progress over SSE.
handleEvents(pkg/web/server.go:284) hands the response to go-sse'sJoeprovider, andJoebroadcasts synchronously:Session.Publishcallssub.Client.Send/Flushfor every subscriber before it returns. A client that stops reading — a closed laptop lid, a frozen tab, a stalled tunnel — fills its socket buffer, andPublishblocks forever. SinceBroadcastLogger.Printpublishes every progress line, the whole run stalls behind that client, andStopTailing/RefreshStatesblock with it.Reproduced against a real socket that sends the SSE request and never reads: with a 4 KiB receive buffer, the fourth 32 KiB event blocks
Publishfor more than three seconds; a goroutine dump showsJoe.start→Client.Send→net.(*conn).Write.Fix
Wrap the response writer in
handleEventsso everyWriteandFlushsets a 10 second deadline withhttp.ResponseController. A stalled subscriber now fails its own write;Joedrops that subscription on the send error and the publisher continues. The deadline is refreshed on every write, so a client that keeps reading is never disconnected, and the browser'sEventSourcereconnects withLast-Event-IDand replays from the existingFiniteReplayer.The wrapper keeps the underlying writer's
FlushErrorvisible, so a failed flush still drops the subscriber the way go-sse did before the wrapper; a writer that supports neitherhttp.FlushernorFlushErroris passed through untouched, so go-sse still rejects it with the same 500.SetWriteDeadlineis best-effort: a writer that does not support it (such ashttptest.ResponseRecorder) keeps the previous behavior.pkg/webserves plain HTTP/1.1, so HTTP/2 is out of scope for this change.Validation
TestServer_HandleEvents_SlowClientDoesNotBlockPublishopens a real socket, never reads it, and publishes 32 KiB events untilhandleEventsreturns: on master the blockedPublishtrips a 3 s guard; with the change the stalled subscriber is dropped at the write deadline and the following publishes stay fast.TestServer_HandleEvents_ActiveClientStaysConnectedkeeps reading and idles longer than the deadline between events, so a deadline that is not refreshed is caught as a dropped subscriber.TestSSEClientWriter_FlushErrorPropagateskeeps the wrapper from hiding the underlying writer'sFlushError, andTestServer_HandleEvents_NonFlusherWriterkeeps the old 500 for a writer without flush support.go test ./pkg/web: passed.go test ./...: the only failure ispkg/progress'sTestNewLogger_HistoryStemCannotEscapeHistoryDirectory(Windows rejects theprogress-..history path); it fails the same way on master.golangci-lint run --max-issues-per-linter=0 --max-same-issues=0 ./...(v2.13.0): 0 issues.gofmt -s,go vet: passed.Agent Yan assisted participation