Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-6783: perf(server): set read-header and idle timeouts on main HTTP server (#7683)
importcppd540eb6fe7f6
diff --git a/server/cmd/server/main.go b/server/cmd/server/main.goindex b40c3ce517..5a5fee3a62 100644--- a/server/cmd/server/main.go+++ b/server/cmd/server/main.go@@ -269,6 +269,23 @@ func jwtSecretBootError(jwtSecret, appEnv string) error {return auth.ValidateJWTSecret(jwtSecret)}+// newMainHTTPServer builds the public HTTP server with the production timeout+// defaults. These values are load-bearing safety settings, not cosmetic tuning,+// so they live in one helper that main() and the config regression test share.+//+// Bound header reads to stop Slowloris; IdleTimeout is looser than the+// metrics/profiling servers' 30s for keep-alive-heavy CLI and daemon clients.+// ReadTimeout and WriteTimeout are deliberately left zero so WebSocket upgrades+// (/ws, /api/daemon/ws) on this listener aren't killed mid-connection.+func newMainHTTPServer(addr string, handler http.Handler) *http.Server {+ return &http.Server{+ Addr: addr,+ Handler: handler,+ ReadHeaderTimeout: 5 * time.Second,+ IdleTimeout: 120 * time.Second,+ }+}+func main() {logger.Init()// Warn about missing configuration@@ -565,10 +582,7 @@ func main() {LLMMaxRetries: llmMaxRetries,})- srv := &http.Server{- Addr: ":" + port,- Handler: r,- }+ srv := newMainHTTPServer(":"+port, r)profilingServer := profiling.NewServer()// Start background workers.diff --git a/server/cmd/server/main_test.go b/server/cmd/server/main_test.goindex a4fe4b5747..26c5c3de20 100644--- a/server/cmd/server/main_test.go+++ b/server/cmd/server/main_test.go@@ -513,3 +513,28 @@ func TestJWTSecretBootError(t *testing.T) {})}}++// TestNewMainHTTPServerTimeouts pins the production timeout defaults on the+// public HTTP server. These are safety settings, not tuning: removing them,+// resetting them to zero, or making ReadTimeout/WriteTimeout non-zero would+// silently reintroduce the Slowloris exposure or start killing uploads and+// long-lived WebSocket connections mid-stream — none of which the rest of the+// suite would catch.+func TestNewMainHTTPServerTimeouts(t *testing.T) {+ srv := newMainHTTPServer(":8080", nil)++ if got, want := srv.ReadHeaderTimeout, 5*time.Second; got != want {+ t.Errorf("ReadHeaderTimeout = %v, want %v", got, want)+ }+ if got, want := srv.IdleTimeout, 120*time.Second; got != want {+ t.Errorf("IdleTimeout = %v, want %v", got, want)+ }+ // Zero is intentional: WebSocket upgrades and large uploads share this+ // listener and must not be bounded by a whole-request deadline.+ if got := srv.ReadTimeout; got != 0 {+ t.Errorf("ReadTimeout = %v, want 0", got)+ }+ if got := srv.WriteTimeout; got != 0 {+ t.Errorf("WriteTimeout = %v, want 0", got)+ }+}