Exempt SSE endpoints from the 60s request timeout middleware#287
Closed
hiroTamada wants to merge 1 commit into
Closed
Exempt SSE endpoints from the 60s request timeout middleware#287hiroTamada wants to merge 1 commit into
hiroTamada wants to merge 1 commit into
Conversation
middleware.Timeout cancels the request context after 60s, which kills
/builds/{id}/events and /instances/{id}/logs streams mid-flight even
while events are flowing. Build-event consumers then observe a closed
stream with the build still in progress and treat it as a failure.
Skip the timeout for streaming paths, mirroring the existing SSE skip
in the HTTP metrics middleware.
|
Created a monitoring plan for this PR. What this PR does: Fixes a bug where long-running builds (>60s) appeared to fail in the eyes of stream consumers — the SSE connection was cut mid-stream, leaving callers with a build stuck in Intended effect:
Risks:
Status updates will be posted automatically on this PR as monitoring progresses. |
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
middleware.Timeout(60 * time.Second)on the authenticated route group cancels the request context after 60s, which hard-kills SSE streams (/builds/{id}/events,/instances/{id}/logs) even while events are actively flowing.building, and misclassifies a successful build as timed out. In production this caused deployments to be marked failed at exactly stream-start+60s while the underlying build succeeded seconds later./logsor/events, mirroring the existing SSE skip in the HTTP metrics middleware directly above. All other routes keep the 60s timeout.Test plan
go build ./cmd/apiandgo vet ./cmd/apipassGET /builds/{id}/events?follow=trueand confirm the stream stays open until the terminal status event🤖 Generated with Claude Code
Note
Low Risk
Narrow routing change for two SSE path suffixes; other endpoints keep the 60s timeout.
Overview
Replaces the blanket 60s
middleware.Timeouton the authenticated API group with a wrapper that bypasses the timeout for paths ending in/logsor/events, while other routes still use the 60s limit.middleware.Timeoutcancels the request context at 60s, which was cutting off long-lived SSE streams (instance logs, build events) even when data was still flowing—e.g. builds over 60s could look failed when the stream died before the terminal status. The skip mirrors the existing HTTP metrics middleware pattern for/logs.Reviewed by Cursor Bugbot for commit d15020d. Bugbot is set up for automated code reviews on this repo. Configure here.