Skip to content

sidecar 契约缺口:壳必须用 --port 0(固定端口会撞 TIME_WAIT;不要加 SO_REUSEADDR) #44

Closed

Description

@Smilewithoutfalling

定性:这是测试工具的问题,加上 sidecar 契约有缺口,不是产品 bug。

现象(沙箱 Linux 实测):连续跑 e2e 时,后端用固定端口 bind,报 Address already in use,因为上一个进程的端口还在 TIME_WAIT。app/server/main.py:49-50 里 bind 前没有设任何 SO_* 选项,默认端口是 8765。

正解:不用固定端口。

  • 契约:桌面壳必须用 --port 0 启动 sidecar,端口从 stdout 第一行的 JSON({"port", "token", "home"})读取。现有机制已经支持,packaging/smoke_sidecar.py 就是这么用的。待办是把这条写进 sidecar 契约文档。
  • 测试工具:e2e 也可以改成 --port 0 加读 stdout;短期做法是每次换一个 E2E_PORT。

不要给 bind 或 uvicorn 加 SO_REUSEADDR:

  • Windows 上能重绑 TIME_WAIT 端口的只有 SO_REUSEADDR,但它同时允许别的进程抢占同一个端口,会破坏"只监听 127.0.0.1、只有本进程能收"这个前提。
  • SO_EXCLUSIVEADDRUSE 防的是别人来抢,不解决 TIME_WAIT,设了只会更严格。
  • 仓库没有声明 requires-python,相关常量要 3.11+,真要设还得做版本兜底。

来源:F3 第二步(PR #43)跑 e2e 时发现;S 10-17 评审后改了定性。

Activity

  1. changed the title [-]后端固定端口重启时可能撞上 TIME_WAIT(bind 没设 SO_REUSEADDR)[/-] [+]sidecar 契约缺口:壳必须用 --port 0(固定端口会撞 TIME_WAIT;不要加 SO_REUSEADDR)[/+] on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions