fix(provider): 延长媒体超时并终止超时轮转
将图像和视频的默认 HTTP/轮询超时分别提高到 20 分钟和 30 分钟。媒体任务超时后直接失败,不再重试、切换客户端或标记为 upstream_submission_unknown。OpenAI 图像端点遇到上游明确拒绝 response_format 时自动移除并缓存兼容结论。 验证:go test ./... -count=1;go vet ./...;gofmt;相关 Shell bash -n、ShellCheck 与发布脚本回归测试。
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/clients"
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/netproxy"
|
||||
@@ -19,8 +18,6 @@ type httpClientCache struct {
|
||||
custom map[string]*http.Client
|
||||
}
|
||||
|
||||
const providerHTTPClientTimeout = 10 * time.Minute
|
||||
|
||||
const (
|
||||
providerHTTPMaxIdleConnections = 2048
|
||||
providerHTTPMaxIdleConnectionsPerHost = 1024
|
||||
@@ -34,16 +31,19 @@ func newHTTPClientCache() *httpClientCache {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) httpClientForCandidate(candidate store.RuntimeModelCandidate, simulated bool) (*http.Client, error) {
|
||||
func (s *Service) httpClientForCandidate(candidate store.RuntimeModelCandidate, simulated bool, kind string) (*http.Client, error) {
|
||||
var client *http.Client
|
||||
if simulated {
|
||||
return s.httpClients.none, nil
|
||||
client = s.httpClients.none
|
||||
return providerHTTPClientForKind(client, kind), nil
|
||||
}
|
||||
// Some Worker sites have direct provider egress but are not authorized to
|
||||
// use a platform's shared proxy. Keep this override explicitly scoped to
|
||||
// platform UUIDs so one site's routing exception cannot bypass proxies for
|
||||
// unrelated providers or platforms.
|
||||
if platformIDListed(s.cfg.PlatformProxyBypassIDs, candidate.PlatformID) {
|
||||
return s.httpClients.none, nil
|
||||
client = s.httpClients.none
|
||||
return providerHTTPClientForKind(client, kind), nil
|
||||
}
|
||||
config, err := netproxy.Normalize(netproxy.FromPlatformConfig(candidate.PlatformConfig))
|
||||
if err != nil {
|
||||
@@ -52,14 +52,22 @@ func (s *Service) httpClientForCandidate(candidate store.RuntimeModelCandidate,
|
||||
switch config.Mode {
|
||||
case netproxy.ModeGlobal:
|
||||
if strings.TrimSpace(s.cfg.GlobalHTTPProxy) != "" {
|
||||
return s.httpClients.customClient(s.cfg.GlobalHTTPProxy)
|
||||
client, err = s.httpClients.customClient(s.cfg.GlobalHTTPProxy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
break
|
||||
}
|
||||
return s.httpClients.global, nil
|
||||
client = s.httpClients.global
|
||||
case netproxy.ModeCustom:
|
||||
return s.httpClients.customClient(config.HTTPProxy)
|
||||
client, err = s.httpClients.customClient(config.HTTPProxy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return s.httpClients.none, nil
|
||||
client = s.httpClients.none
|
||||
}
|
||||
return providerHTTPClientForKind(client, kind), nil
|
||||
}
|
||||
|
||||
func platformIDListed(raw string, platformID string) bool {
|
||||
@@ -100,7 +108,16 @@ func newHTTPClient(proxy func(*http.Request) (*url.URL, error)) *http.Client {
|
||||
transport.MaxIdleConns = providerHTTPMaxIdleConnections
|
||||
transport.MaxIdleConnsPerHost = providerHTTPMaxIdleConnectionsPerHost
|
||||
return &http.Client{
|
||||
Timeout: providerHTTPClientTimeout,
|
||||
Timeout: clients.ProviderRequestTimeout(""),
|
||||
Transport: transport,
|
||||
}
|
||||
}
|
||||
|
||||
func providerHTTPClientForKind(base *http.Client, kind string) *http.Client {
|
||||
if base == nil || base.Timeout == clients.ProviderRequestTimeout(kind) {
|
||||
return base
|
||||
}
|
||||
client := *base
|
||||
client.Timeout = clients.ProviderRequestTimeout(kind)
|
||||
return &client
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user