fix: serve HTTP server has no read/write/idle deadlines, so slow clients can pin handlers and block shutdown#875
Closed
sam-saffron-jarvis wants to merge 1 commit into
Conversation
…nts can pin handlers and block shutdown
Owner
|
Implemented in local copy: serve HTTP server now has read-header/idle timeouts while keeping global WriteTimeout unset for SSE, and streaming endpoints use a per-write deadline wrapper. Verified with go build ./... and targeted tests. |
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 changed
ReadHeaderTimeoutandIdleTimeouton the serve HTTP server incmd/serve.go.WriteTimeoutat zero so long-lived SSE endpoints do not get an artificial lifetime cap.streamingResponseWriterwrapper that applies a per-writeSetWriteDeadlinearound every streamingWriteandFlushcall./v1/chat/completions,/v1/messages, and response-run SSE streams) with that writer so slow or stalled clients cannot block a handler forever.Why this is high-value
Before this change,
serveServer.Startcreated anhttp.Serverwith no read-header or idle deadlines, and the streaming handlers wrote directly tohttp.ResponseWriter/Flushwith no per-connection write deadline. That meant:contextWithShutdowntries to make them exit promptly.This fix closes those reliability holes without breaking long-lived streaming behavior.
Validation
gofmt -w cmd/serve.go cmd/serve_protocol.go cmd/serve_handlers_chat.go cmd/serve_handlers_anthropic.go cmd/serve_response_runs.go cmd/serve_test.go cmd/serve_protocol_test.gogo build ./...go test ./...git diff --check