Skip to content

fix: add relay idle connection timeout config - #5309

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/idle-timeout
Jun 5, 2026
Merged

fix: add relay idle connection timeout config#5309
seefs001 merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/idle-timeout

Conversation

@seefs001

@seefs001 seefs001 commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

支持配置http client的idle timeout,默认为golang net/http的默认值90s

环境变量 RELAY_IDLE_CONN_TIMEOUT

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • New Features

    • Added support for configuring idle connection timeout in relay HTTP clients. Users can now set RELAY_IDLE_CONN_TIMEOUT environment variable (default: 90 seconds) to customize idle keep-alive timeout; set to 0 to disable.
  • Documentation

    • Updated README and environment configuration examples with new relay timeout setting.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

A new idle connection timeout configuration is introduced for relay HTTP clients. The setting is declared as a global constant, initialized from the RELAY_IDLE_CONN_TIMEOUT environment variable with a 90-second default, documented in configuration examples and the README, and applied uniformly to all HTTP transport instances used by the service.

Changes

Relay Idle Connection Timeout Configuration

Layer / File(s) Summary
Configuration constant declaration
common/constants.go
New exported variable RelayIdleConnTimeout (int, seconds) is declared alongside other relay timeout settings.
Configuration documentation and examples
.env.example, README.md, docker-compose.yml
Configuration examples and deployment documentation are updated to describe RELAY_IDLE_CONN_TIMEOUT, its default of 90 seconds, and how to disable it with 0.
Configuration initialization
common/init.go
Environment variable RELAY_IDLE_CONN_TIMEOUT is read during InitEnv() and stored in RelayIdleConnTimeout using GetEnvOrDefault with default 90.
HTTP transport idle timeout application
service/http_client.go
The configured timeout is applied to the IdleConnTimeout field of three HTTP transport instances: base client, HTTP/HTTPS proxy client, and SOCKS5/SOCKS5H proxy client, each converted to time.Duration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A timeout so fine, for connections idle—
ninety seconds by default, no need to whittle.
Through env vars and proxies, the config flows free,
from constant to transport, a timeout decree! 🌰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding relay idle connection timeout configuration across multiple files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 87cc22d and 316b621.

📒 Files selected for processing (6)
  • .env.example
  • README.md
  • common/constants.go
  • common/init.go
  • docker-compose.yml
  • service/http_client.go

Comment thread .env.example
Comment on lines +59 to +60
# Relay HTTP 客户端空闲连接超时时间,单位秒,默认跟随 Go 标准库,设置为0表示不限制
# RELAY_IDLE_CONN_TIMEOUT=90

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Comment thread docker-compose.yml
- 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Comment thread README.md
| `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` |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

@seefs001
seefs001 merged commit 933ea0c into QuantumNous:main Jun 5, 2026
2 checks passed
Soein added a commit to Soein/new-api that referenced this pull request Jun 6, 2026
… 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 ✅
Ember-Moth pushed a commit to Ember-Moth/new-api that referenced this pull request Jun 7, 2026
szxufan pushed a commit to szxufan/new-api that referenced this pull request Jun 9, 2026
52assert added a commit to 52assert/new-api that referenced this pull request Jun 10, 2026
…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
endercat-alu pushed a commit to endercat-alu/new-api that referenced this pull request Jun 10, 2026
OuYang-HX pushed a commit to OuYang-HX/new-api that referenced this pull request Jun 13, 2026
YeMao11 pushed a commit to YeMao11/new-api that referenced this pull request Jun 16, 2026
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>
YeMao11 pushed a commit to YeMao11/new-api that referenced this pull request Jun 16, 2026
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>
ruanhangjian pushed a commit to ruanhangjian/new-api that referenced this pull request Jul 11, 2026
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant