fix: add relay idle connection timeout config - #5309
Conversation
WalkthroughA new idle connection timeout configuration is introduced for relay HTTP clients. The setting is declared as a global constant, initialized from the ChangesRelay Idle Connection Timeout Configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.env.example:
- Around line 59-60: The comment for RELAY_IDLE_CONN_TIMEOUT is ambiguous about
whether it dynamically follows Go's stdlib or is a fixed default; update the
.env.example comment to state the explicit default used by the code: mention
"默认为 90 秒(与 Go 标准库一致)" so it matches the behavior from
GetEnvOrDefault("RELAY_IDLE_CONN_TIMEOUT", 90) in common/init.go and references
RELAY_IDLE_CONN_TIMEOUT clearly.
In `@docker-compose.yml`:
- Line 37: Update the commented description for RELAY_IDLE_CONN_TIMEOUT to
reflect the actual default used in code: change "默认跟随 Go 标准库" to "默认为 90 秒(与 Go
标准库一致)" so the docker-compose comment matches the hardcoded default in
common/init.go (see the 90s default set in common/init.go:105) and clearly
indicate the unit is seconds and that 0 disables the limit.
In `@README.md`:
- Line 319: Update the README entry for RELAY_IDLE_CONN_TIMEOUT to explicitly
state the hardcoded default of 90 seconds rather than saying "Go standard
library behavior"; change the description to something like "Idle keep-alive
timeout for relay HTTP clients, seconds. Default is 90 (matching Go standard
library); set 0 to disable" so it matches the actual default set in the code
where RELAY_IDLE_CONN_TIMEOUT is initialized.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 07856e2e-6f32-46fc-a3c1-9d68223c5354
📒 Files selected for processing (6)
.env.exampleREADME.mdcommon/constants.gocommon/init.godocker-compose.ymlservice/http_client.go
| # Relay HTTP 客户端空闲连接超时时间,单位秒,默认跟随 Go 标准库,设置为0表示不限制 | ||
| # RELAY_IDLE_CONN_TIMEOUT=90 |
There was a problem hiding this comment.
Clarify the default behavior description.
The comment states "默认跟随 Go 标准库" (defaults to Go standard library), but looking at common/init.go:105, the code explicitly sets GetEnvOrDefault("RELAY_IDLE_CONN_TIMEOUT", 90). While 90 seconds matches Go's http.Transport default, the current phrasing suggests the value dynamically follows the standard library rather than being hardcoded. Consider revising to: "默认为 90 秒(与 Go 标准库一致)" (defaults to 90 seconds, matching Go standard library) for clarity.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.env.example around lines 59 - 60, The comment for RELAY_IDLE_CONN_TIMEOUT
is ambiguous about whether it dynamically follows Go's stdlib or is a fixed
default; update the .env.example comment to state the explicit default used by
the code: mention "默认为 90 秒(与 Go 标准库一致)" so it matches the behavior from
GetEnvOrDefault("RELAY_IDLE_CONN_TIMEOUT", 90) in common/init.go and references
RELAY_IDLE_CONN_TIMEOUT clearly.
| - BATCH_UPDATE_ENABLED=true # 是否启用批量更新 (Whether to enable batch update) | ||
| - NODE_NAME=new-api-node-1 # 节点名称,用于审计日志中标识节点身份;多节点/容器部署时建议设置 (Node name used in audit logs; recommended when running multiple instances or in containers) | ||
| # - STREAMING_TIMEOUT=300 # 流模式无响应超时时间,单位秒,默认120秒,如果出现空补全可以尝试改为更大值 (Streaming timeout in seconds, default is 120s. Increase if experiencing empty completions) | ||
| # - RELAY_IDLE_CONN_TIMEOUT=90 # Relay HTTP 客户端空闲连接超时时间,单位秒,默认跟随 Go 标准库,设置为0表示不限制 (Relay HTTP client idle keep-alive timeout in seconds, defaults to Go standard library; set 0 to disable) |
There was a problem hiding this comment.
Clarify the default behavior description.
The comment states "默认跟随 Go 标准库" (defaults to Go standard library), but the code in common/init.go:105 explicitly sets a hardcoded default of 90 seconds. Consider revising to: "默认为 90 秒(与 Go 标准库一致)" (defaults to 90 seconds, matching Go standard library) to accurately reflect the implementation.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docker-compose.yml` at line 37, Update the commented description for
RELAY_IDLE_CONN_TIMEOUT to reflect the actual default used in code: change "默认跟随
Go 标准库" to "默认为 90 秒(与 Go 标准库一致)" so the docker-compose comment matches the
hardcoded default in common/init.go (see the 90s default set in
common/init.go:105) and clearly indicate the unit is seconds and that 0 disables
the limit.
| | `CRYPTO_SECRET` | Encryption secret (required for Redis) | - | | ||
| | `SQL_DSN` | Database connection string | - | | ||
| | `REDIS_CONN_STRING` | Redis connection string | - | | ||
| | `RELAY_IDLE_CONN_TIMEOUT` | Idle keep-alive timeout for relay HTTP clients, seconds. Defaults to Go standard library behavior; set `0` to disable | `90` | |
There was a problem hiding this comment.
Clarify the default behavior description.
The description states "Defaults to Go standard library behavior" but common/init.go:105 explicitly hardcodes the default to 90 seconds. While this value matches Go's http.Transport default, the current wording suggests dynamic behavior. Consider revising to: "Idle keep-alive timeout for relay HTTP clients, seconds. Default is 90 (matching Go standard library); set 0 to disable" for clarity.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@README.md` at line 319, Update the README entry for RELAY_IDLE_CONN_TIMEOUT
to explicitly state the hardcoded default of 90 seconds rather than saying "Go
standard library behavior"; change the description to something like "Idle
keep-alive timeout for relay HTTP clients, seconds. Default is 90 (matching Go
standard library); set 0 to disable" so it matches the actual default set in the
code where RELAY_IDLE_CONN_TIMEOUT is initialized.
… id 等) 主要变更(QuantumNous/new-api → adc390c): - feat: 渠道被禁用后可配置是否清空渠道粘性 (QuantumNous#5306) - feat(web): profile 页显示 user id (QuantumNous#5317) - fix: 复用 channel handler 的 stream scanner buffer (QuantumNous#5225) - fix: 收窄 OpenAI o 系列模型适配范围 (QuantumNous#5293) - fix(relay): GLM Anthropic 兼容避免 chunked encoding (QuantumNous#5307) - fix: 新增 relay idle 连接超时配置 (QuantumNous#5309) - fix: 限制匿名请求体大小 (QuantumNous#5244) - fix(distributor): 修复 video generations task_id 模型解析 (QuantumNous#5133) - fix(dify): 远程图片字段赋值前初始化 file pointer (QuantumNous#5134) - fix(i18n): 优化 thinking adapter 文案 (QuantumNous#5242) 去合规一致性:上游未触及任何合规文件,合并完整保留本地去合规状态 (payment_setting.go / payment-settings-section.tsx / recharge-form-card.tsx / risk-acknowledgement-dialog.tsx 均未被改动)。 i18n:web/default 6 语言(en/zh/fr/ja/ru/vi)key 并集三路合并 + i18n:sync 规范化,4584 keys/语言,missing/extras/untranslated 全为 0。 验证:go build ./... ✅ + bun run typecheck ✅
…codes * origin/main: (45 commits) fix(openai): support streaming image relay and image edit for images API (QuantumNous#4608) perf(web): improve dialog sizing and footer layout feat(web): add shared dialog wrapper perf(web): simplify public page hero copy perf(model-pricing): move pricing tabs into page title feat(json-editor): add reusable JSON code editor perf(model-pricing): improve JSON pricing editor layout perf(model-pricing): reduce duplicate model name display fix: support six-decimal steps in model pricing editor fix: respect theme for multiselect combobox popover fix: reuse stream scanner buffer in channel handlers (QuantumNous#5225) fix: 收窄 OpenAI o 系列模型适配范围 (QuantumNous#5293) fix(i18n): clarify thinking adapter copy (QuantumNous#5242) fix: limit anonymous request body (QuantumNous#5244) fix(relay): fix Anthropic-compatible compatibility for GLM (avoid chunked encoding) (QuantumNous#5307) feat: 支持配置渠道被禁用后是否清空渠道粘性 (QuantumNous#5306) fix: add relay idle connection timeout config (QuantumNous#5309) feat(web): show user id on profile page perf(model-pricing): refine visual editor actions refactor(model-pricing): split visual pricing editor modules ... # Conflicts: # router/api-router.go # web/default/src/features/usage-logs/components/usage-logs-mobile-card.tsx
(cherry picked from commit 933ea0c)
Upstream changes (50+ commits, v1.0.0-rc.11): - data-table perf: row selection memo, column pinning, badge display - Fixes: channel test dialog (QuantumNous#5517), CC Switch model selector (QuantumNous#5515), API key form options (QuantumNous#5512), cell overflow (QuantumNous#5510), kimi k2.6 temp (QuantumNous#5390), Anthropic-compatible GLM chunked encoding (QuantumNous#5307), streaming image relay (QuantumNous#4608) - Feat: audit auth method tracking (QuantumNous#5462), channel affinity clear toggle (QuantumNous#5306), relay idle timeout config (QuantumNous#5309), 6-decimal pricing precision (QuantumNous#5332) - Classic frontend: Rsbuild support, Semi React 19 adapter - Shared dialog wrapper, JSON code editor, debounce channel search Conflict resolved: web/bun.lock (accepted upstream, will regenerate) Co-Authored-By: Claude <noreply@anthropic.com>
Merge upstream v1.0.0-rc.11 (50+ commits): - data-table perf: row selection memo, column pinning, badge display - Fixes: channel test dialog (QuantumNous#5517), CC Switch (QuantumNous#5515), API key (QuantumNous#5512), kimi k2.6 temp (QuantumNous#5390), GLM chunked encoding (QuantumNous#5307), streaming image (QuantumNous#4608) - Feat: audit auth tracking (QuantumNous#5462), channel affinity toggle (QuantumNous#5306), relay idle timeout (QuantumNous#5309), 6-decimal pricing (QuantumNous#5332) - Shared dialog wrapper, JSON code editor, classic Rsbuild support SEO optimization: - robots.txt: 10 AI crawler blocks + 22 path disallows + crawl-delay - sitemap.xml: 7 public URLs with 6-language hreflang annotations - index.html: hreflang tags, og:locale:alternate, og:image, canonical, 5 structured data types (Organization, SoftwareApplication, FAQPage, WebSite, SearchAction), expanded keywords (gateway, agent router, aggregation, orchestration) - i18n/config.ts: sync <html lang> with active language for SEO Co-Authored-By: Claude <noreply@anthropic.com>
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
支持配置http client的idle timeout,默认为golang net/http的默认值90s
环境变量 RELAY_IDLE_CONN_TIMEOUT
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
Summary by CodeRabbit
New Features
RELAY_IDLE_CONN_TIMEOUTenvironment variable (default: 90 seconds) to customize idle keep-alive timeout; set to 0 to disable.Documentation