From 20945dbbcb4fb4142c407d3fd8428ba7983399dd Mon Sep 17 00:00:00 2001 From: wangbo Date: Fri, 24 Jul 2026 13:42:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(runner):=20=E5=BB=B6=E9=95=BF=E5=AA=92?= =?UTF-8?q?=E4=BD=93=E4=B8=8A=E6=B8=B8=E8=AF=B7=E6=B1=82=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 图像生成上游同步响应可能超过 120 秒,原共享 HTTP 客户端会把仍在处理的提交标记为结果不确定。将客户端超时调整为 10 分钟,并增加回归测试;任务执行仍由现有租约、任务超时和取消机制约束。\n\n验证:\n- env -u AI_GATEWAY_TEST_DATABASE_URL go test ./internal/runner -run 'TestProviderHTTPClientTimeoutAllowsLongRunningMediaRequests|TestPlatformProxyMode' -count=1\n- env -u AI_GATEWAY_TEST_DATABASE_URL go test ./... -count=1 --- apps/api/internal/runner/proxy.go | 4 +++- apps/api/internal/runner/proxy_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/api/internal/runner/proxy.go b/apps/api/internal/runner/proxy.go index f650ada..9f74f10 100644 --- a/apps/api/internal/runner/proxy.go +++ b/apps/api/internal/runner/proxy.go @@ -19,6 +19,8 @@ type httpClientCache struct { custom map[string]*http.Client } +const providerHTTPClientTimeout = 10 * time.Minute + func newHTTPClientCache() *httpClientCache { return &httpClientCache{ none: newHTTPClient(nil), @@ -67,7 +69,7 @@ func newHTTPClient(proxy func(*http.Request) (*url.URL, error)) *http.Client { transport := http.DefaultTransport.(*http.Transport).Clone() transport.Proxy = proxy return &http.Client{ - Timeout: 120 * time.Second, + Timeout: providerHTTPClientTimeout, Transport: transport, } } diff --git a/apps/api/internal/runner/proxy_test.go b/apps/api/internal/runner/proxy_test.go index ebb8aca..cd6c385 100644 --- a/apps/api/internal/runner/proxy_test.go +++ b/apps/api/internal/runner/proxy_test.go @@ -5,11 +5,19 @@ import ( "net/http" "net/http/httptest" "testing" + "time" "github.com/easyai/easyai-ai-gateway/apps/api/internal/config" "github.com/easyai/easyai-ai-gateway/apps/api/internal/store" ) +func TestProviderHTTPClientTimeoutAllowsLongRunningMediaRequests(t *testing.T) { + client := newHTTPClient(nil) + if client.Timeout != 10*time.Minute { + t.Fatalf("unexpected provider HTTP timeout: got %s want %s", client.Timeout, 10*time.Minute) + } +} + func TestPlatformProxyModeNoneIgnoresEnvironmentProxy(t *testing.T) { var proxyHits int proxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {