Skip to content

[PR] fix: keep listen retries within the valid port range - #7362

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-20_bound-listen-retry-ports
Nov 20, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-20_bound-listen-retry-ports

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Problem

Port 65535 is accepted as a zone base or sticky port. If a launcher-managed listener must move off it while retry attempts remain, both the EADDRINUSE policy and the post-bind ownership policy return 65536. Node rejects that value with ERR_SOCKET_BAD_PORT, preventing startup on a supported configuration.

Changes

Share the retry-port calculation between both policies. Exhausting the numeric port range now chooses the existing port-0 fallback, just as exhausting the retry budget does. A retry from 65534 still tries 65535.

The calculation remains after the existing retry-rights checks. Strict-port/manual launches, upgrade replacements, proven twins/newer holders and predecessor waits retain their existing outcomes.

Verification

  • Tested base: 1e357bf2d6632bfbd2a74ffb70ecee1af1ec7cc3 (current master, 0.1.216).
  • Before the fix: 2 regressions fail when the production decisions reach real net.Server.listen calls with port 65536; 2 controls pass.
  • After the fix: 57 targeted tests pass across listen-retry-boundary, listen-policy, port-owner and port-zone. Both boundary retries bind OS-assigned ports, with no assumption that a fixed port is free.
  • npm run typecheck, npm run build, npm run check:unused-exports, npm run check:test-import-graph and git diff --check: passed.
  • Published tree eed65d72a6db4d2f85974ad864fe19b1a11b0970 exactly matches the locally validated tree.
  • Node 24.22.3 / Linux x86_64. No live host-client or Windows run; the full-suite verdict remains repository CI on this head.

Related #1670, #3055 and #2947 established the existing zone/replacement/ownership contracts. This fixes the remaining port-range boundary in both retry paths as one change.

Fixes #7361

@ranxianglei ranxianglei changed the title fix: keep listen retries within the valid port range [PR] fix: keep listen retries within the valid port range Nov 20, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 Searched open+closed issues and PRs for the failure signature (65536, ERR_SOCKET_BAD_PORT): the only matches are #7361 (this bug) and this PR. The related contracts #1670/#3055/#2947 are the zone/replacement/ownership foundations this builds on, not parallel fixes. No other open PR targets this thread.

Review — PR #7362 (head bf39ca608f0, base 1e357bf2d66 = current master)

Direction (①). Issue #7361 asks: when the numeric port range ends, use the existing port-0 fallback; 65534 must still advance to 65535; strict/manual/replacement/predecessor precedence untouched. The PR does exactly that. I verified the boundary is reachable through both documented entry points: resolveZonePortBase (src/config.ts:2917) accepts fromEnv < 65536, and readZonePort (src/instance.ts:110) accepts the same range from the sticky record. The fix lands at the decision point (the producer of the invalid value), not at the listen call — root-cause, not a mask.

Regression audit (②). Existing behaviors on every touched path, item by item:

  • decideEaddrinuse (src/listen-policy.ts): twin-collision, upgrade-replacement (wait/fail), strict-port / no-launch-token / budget-exhausted fail-fast, and predecessor-wait are all early branches BEFORE the ladder line — untouched, and the new test 4 pins strict-port / no-token / upgrade-replacement / predecessor-wait / post-bind die.
  • Ladder 65534→65535 preserved (test 3 pins it on both paths); budget exhaustion → 0 preserved. The ===→>= unification in nextListenPort is behavior-neutral for decideEaddrinuse: the guard ctx.attempts >= ctx.maxAttempts fail-fasts before the ladder line, so nextAttempts <= maxAttempts there; resolvePortClaim already used >=.
  • resolvePortClaim (src/port-owner.ts): claimed and die outcomes untouched.
  • server.ts call sites untouched: both log lines already render nextPort === 0 as "retrying on an ephemeral port", and attemptListen(0) is the established budget-exhaustion path.
  • Grep of src/ confirms these two retry paths are the ONLY port-increment sites; no third path has the same boundary.
  • The single behavior change is 65535 → 0 where it was 65536. The old value was never consumable (Node rejects it with ERR_SOCKET_BAD_PORT), so nothing could have depended on it. Intended fix, disclosed in the PR body.

Code (③). nextListenPort is a small pure function with a why-comment; the 65535 boundary matches the existing v < 65536 validation style in config.ts/instance.ts. No dead code, no new dependencies, style consistent.

Tests (④). Real teeth, verified locally: with the PRE-fix src/listen-policy.ts + src/port-owner.ts, the two new regression tests fail with exactly ERR_SOCKET_BAD_PORT while the two controls pass; at the PR head all 57 targeted tests pass (listen-retry-boundary, listen-policy, port-owner, port-zone). The boundary tests drive the production entry points into a real net.Server.listen on port 0 — no fixed-port-free assumption.

Diff (⑤). 3 files, 75+/2−, every line on-topic, no whitespace churn, no unrelated files.

CI. Head bf39ca608f0: 57 success / 27 skipped (gated e2e lanes — this file list doesn't trigger them) / 0 failures; all 11 test shards green (ubuntu+windows × node 22/24). The PR body's "no Windows run" refers to the author's local harness; CI covers Windows. PR-body claims independently verified: base is master tip, head tree eed65d72a6… matches, 57-test count reproduces.

结构化八问

  1. 是什么问题: zone 端口取最大合法值 65535(BILI_ZONE_PORT=65535 或 sticky zone 记录)且该端口被占用时,两条重试路径都算出 65536,Node 以 ERR_SOCKET_BAD_PORT 拒绝,launcher 托管的 proxy 无法启动。
  2. 什么原因导致的: 两条重试决策点(pre-bind 的 EADDRINUSE 策略、post-bind 的 ownership 策略)各自独立做 lastTriedPort + 1,都没有对数值端口范围做上界钳制——无效值的生产者在决策函数里,不在 listen 调用处。
  3. 影响范围与严重程度: 仅影响显式把 zone 端口配到 65535 的 launcher 托管 proxy,且仅当该端口被占用时;此时启动完全失败、无回退。p1(该配置下不可用)。
  4. 怎么修复的: 抽出共享纯函数 nextListenPort——重试预算耗尽或数值端口范围耗尽(port >= 65535)时,统一返回既有的 port-0(OS 临时端口)回退;两条策略复用同一计算,65534 仍照常推进到 65535。
  5. 是否有回归问题: 无。逐项审过:twin-collision / upgrade-replacement / strict-port / 无 launch token / 预算耗尽 fail-fast / predecessor wait 均为 ladder 行之前的早退分支,未触碰且有测试钉住;resolvePortClaim 的 claimed/die 未变;===→>= 合并行为中性(guard 保证 ladder 行前 attempts < maxAttempts,port-owner 原本就是 >=);唯一行为变化是 65535→0(旧值 65536 从来不可消费),即本 PR 的目标修复且已在正文披露;src/ 内无其他 port+1 路径。
  6. 是否破坏缓存: 不涉及——不触碰任何缓存、去重键或游标。
  7. 是否改了设计方向: 否——仅把两处重复计算收敛为一个共享决策函数,无架构/数据流变化。
  8. 是否引入了新的配置: 否——无新 env/config/flag;BILI_ZONE_PORT=65535 原本就被接受,只是边界行为从崩溃改为临时端口回退。

判定: 可合。 同时满足 §7.4 auto-merge 门禁(单机制修复、回归测试在修复前红/修复后绿、rebased head 上 CI 全绿、无 config/persistence/wire/kernel 变更、纯 fix、diff 干净、Fixes #7361、不碰 load-bearing 基础设施)——合并由 owner 执行。

标签: #7361 打 bug + p1 + scope/other(受支持配置导致启动失败=可用性缺陷;launcher 启动域,跨宿主车道无单一 host-lane 标签);PR #7362 按自身 diff 打 bug + p1 + scope/other(保留既有 root-cause)。

@ranxianglei
ranxianglei merged commit 2e2c68a into ranxianglei:master Nov 20, 2026
120 of 156 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Retrying a valid highest zone port attempts invalid port 65536

2 participants