fix(流式): 提升SSE稳定性并统一超时配置
- 扩展SSE行长与间隔超时处理,补充keepalive - 写入失败与超长行时发送错误事件,修复并发释放 - 同步默认配置与示例配置,更新Caddy超时/压缩规则 - 新增OpenAI流式超时与超长行测试 测试: go test ./...
This commit is contained in:
@@ -25,8 +25,8 @@
|
||||
timeouts {
|
||||
read_body 30s
|
||||
read_header 10s
|
||||
write 60s
|
||||
idle 120s
|
||||
write 300s
|
||||
idle 300s
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,10 @@ example.com {
|
||||
write_buffer 16KB
|
||||
compression off
|
||||
}
|
||||
|
||||
|
||||
# SSE/流式传输优化:禁用响应缓冲,立即刷新数据给客户端
|
||||
flush_interval -1
|
||||
|
||||
# 故障转移
|
||||
fail_duration 30s
|
||||
max_fails 3
|
||||
@@ -92,6 +95,10 @@ example.com {
|
||||
gzip 6
|
||||
minimum_length 256
|
||||
match {
|
||||
# SSE 请求通常会带 Accept: text/event-stream,需排除压缩
|
||||
not header Accept text/event-stream*
|
||||
# 排除已知 SSE 路径(即便 Accept 缺失)
|
||||
not path /v1/messages /v1/responses /responses /antigravity/v1/messages /v1beta/models/* /antigravity/v1beta/models/*
|
||||
header Content-Type text/*
|
||||
header Content-Type application/json*
|
||||
header Content-Type application/javascript*
|
||||
@@ -179,6 +186,3 @@ example.com {
|
||||
# =============================================================================
|
||||
# HTTP 重定向到 HTTPS (Caddy 默认自动处理,此处显式声明)
|
||||
# =============================================================================
|
||||
; http://example.com {
|
||||
; redir https://{host}{uri} permanent
|
||||
; }
|
||||
|
||||
@@ -70,7 +70,7 @@ security:
|
||||
# =============================================================================
|
||||
gateway:
|
||||
# 等待上游响应头超时时间(秒)
|
||||
response_header_timeout: 300
|
||||
response_header_timeout: 600
|
||||
# 请求体最大字节数(默认 100MB)
|
||||
max_body_size: 104857600
|
||||
# 连接池隔离策略:
|
||||
@@ -82,14 +82,20 @@ gateway:
|
||||
max_idle_conns: 240
|
||||
max_idle_conns_per_host: 120
|
||||
max_conns_per_host: 240
|
||||
idle_conn_timeout_seconds: 300
|
||||
idle_conn_timeout_seconds: 90
|
||||
# 上游连接池客户端缓存配置
|
||||
# max_upstream_clients: 最大缓存客户端数量,超出后淘汰最久未使用的
|
||||
# client_idle_ttl_seconds: 客户端空闲回收阈值(秒),超时且无活跃请求时回收
|
||||
max_upstream_clients: 5000
|
||||
client_idle_ttl_seconds: 900
|
||||
# 并发槽位过期时间(分钟)
|
||||
concurrency_slot_ttl_minutes: 15
|
||||
concurrency_slot_ttl_minutes: 30
|
||||
# 流数据间隔超时(秒),0=禁用
|
||||
stream_data_interval_timeout: 180
|
||||
# 流式 keepalive 间隔(秒),0=禁用
|
||||
stream_keepalive_interval: 10
|
||||
# SSE 单行最大字节数(默认 10MB)
|
||||
max_line_size: 10485760
|
||||
# Log upstream error response body summary (safe/truncated; does not log request content)
|
||||
log_upstream_error_body: false
|
||||
# Max bytes to log from upstream error body
|
||||
@@ -99,6 +105,13 @@ gateway:
|
||||
# Allow failover on selected 400 errors (default off)
|
||||
failover_on_400: false
|
||||
|
||||
# =============================================================================
|
||||
# 并发等待配置
|
||||
# =============================================================================
|
||||
concurrency:
|
||||
# 并发等待期间的 SSE ping 间隔(秒)
|
||||
ping_interval: 10
|
||||
|
||||
# =============================================================================
|
||||
# Database Configuration (PostgreSQL)
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user