From d15020d6a1c83ee76c22fa5aa9d41e0f9395088f Mon Sep 17 00:00:00 2001 From: hiroTamada <88675973+hiroTamada@users.noreply.github.com> Date: Wed, 10 Jun 2026 16:16:09 +0000 Subject: [PATCH] Exempt SSE endpoints from the 60s request timeout middleware 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. --- cmd/api/main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/api/main.go b/cmd/api/main.go index da2a2326..07b5f76c 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -453,7 +453,19 @@ func run() error { }) } - r.Use(middleware.Timeout(60 * time.Second)) + // Skip the request timeout for SSE streaming endpoints (instance logs, + // build events): middleware.Timeout cancels the request context, which + // kills long-lived streams at 60s even while events are flowing. + r.Use(func(next http.Handler) http.Handler { + timeoutHandler := middleware.Timeout(60 * time.Second)(next) + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if strings.HasSuffix(r.URL.Path, "/logs") || strings.HasSuffix(r.URL.Path, "/events") { + next.ServeHTTP(w, r) + return + } + timeoutHandler.ServeHTTP(w, r) + }) + }) // OpenAPI request validation with authentication validatorOptions := &nethttpmiddleware.Options{