Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-7055: extend search statement timeout to 5 seconds (#8098)
Multica Evec01f60fb0368
diff --git a/server/internal/handler/search.go b/server/internal/handler/search.goindex 5c4dd626ba..bc695aaca1 100644--- a/server/internal/handler/search.go+++ b/server/internal/handler/search.go@@ -25,15 +25,16 @@ import (// therefore still make either path slow enough that the frontend appears to// hang ("搜索卡死没有任何反应", MUL-4059).//-// The 3 s cap leaves margin above the production-observed candidate-first-// maximum (1.72 s in the MUL-7055 matrix) and is short enough that the-// frontend's implicit request timeout (browser default, ~30 s) never kicks in.-// On timeout the caller sees a 503 with a descriptive error rather than a-// stalled connection — SearchIssues / SearchProjects map SQLSTATE 57014 to-// http.StatusServiceUnavailable so the frontend can distinguish this from a-// generic 500.+// The 5 s cap leaves headroom above the production-observed candidate-first+// maximum (1.79 s in the MUL-7055 matrix) while keeping a bounded database+// safety fuse. Interactive web callers cancel superseded searches, and the+// mobile API client has a 30 s request timeout, so this remains within the+// first-party clients' request budgets. On timeout the caller sees a 503 with+// a descriptive error rather than a stalled connection — SearchIssues /+// SearchProjects map SQLSTATE 57014 to http.StatusServiceUnavailable so the+// frontend can distinguish this from a generic 500.const (- searchStatementTimeout = 3 * time.Second+ searchStatementTimeout = 5 * time.SecondsearchWorkMemEnv = "DATABASE_SEARCH_WORK_MEM_MB"defaultSearchWorkMemMB = 64@@ -168,10 +169,10 @@ func runSearchQuery(}// isSearchStatementTimeout reports whether err is the canonical Postgres-// query_canceled error (SQLSTATE 57014). Both `SET LOCAL statement_timeout`-// firing and a client-side context cancellation surface as 57014 — the two-// are indistinguishable from the client side, which is intentional in the-// pgx layer.+// query_canceled error (SQLSTATE 57014) produced when the transaction-local+// statement timeout fires. A client-side context cancellation surfaces from+// pgx as context.Canceled instead, so it is intentionally not classified as a+// database statement timeout here.func isSearchStatementTimeout(err error) bool {if err == nil {return falsediff --git a/server/internal/handler/search_timeout_test.go b/server/internal/handler/search_timeout_test.goindex 5f9119ce52..8aaaf59f2a 100644--- a/server/internal/handler/search_timeout_test.go+++ b/server/internal/handler/search_timeout_test.go@@ -62,7 +62,7 @@ func TestParseSearchWorkMemMB(t *testing.T) {// TestRunSearchQuery_StatementTimeoutFires exercises the safety net end// to end against a live Postgres, proving that a deliberately hung// pg_sleep query is cut off by SET LOCAL statement_timeout (SQLSTATE-// 57014) before the 3 s search cap could ever be reached. Skips+// 57014) before the production search cap could ever be reached. Skips// gracefully if the database is not reachable — mirrors the pattern in// handler_test.go so CI without a DB stays green.func TestRunSearchQuery_StatementTimeoutFires(t *testing.T) {