Conversation
Collaborator
Closed
Collaborator
This was referenced Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #47
Windows 重启后 winnat(Hyper-V/WSL/Docker 依赖)会随机保留若干段 TCP 端口,当默认
proxy_port: 3456落入保留段时,cdp-proxy bind 失败退出,Browser Runtime 永远无法启动(详见 Issue)。本 PR 扩展ensure_runtime()的端口回退条件,使「端口无响应且无法 bind」的场景也能自动换到可用端口,复用现有回退机制,改动最小化。问题回顾
ensure_runtime()原有的端口回退只在「端口被其他 HTTP 服务占用」(health 返回非 bosshunter 标识)时触发:端口被系统保留时:无进程监听 →
health为None;bind 报EACCES。两个信号原代码都没有利用。改动内容
1.
src/bosshunter/browser/runtime/__init__.py—ensure_runtime()回退条件从单一场景扩展为两种:
复用现有的
_find_available_runtime_port()(bind 探测扫描proxy_port+1起 100 个端口,被保留的端口会自动跳过)和_switch_runtime_port()(已同时更新进程级配置,Web 控制台与 CLI 的所有浏览器操作都经由此处,无需其他改动)。2. 同文件 —
_is_port_available()移除
SO_REUSEADDR:Windows 上该选项允许绑定已被其他进程监听的端口,会使探测误报「端口可用」。移除后顺带让「端口被静默非 HTTP 服务占用」的场景也能正确触发回退。3.
tests/test_browser_runtime.py新增
test_ensure_runtime_uses_next_free_port_when_default_is_system_reserved:mock「配置端口无响应 + bind 失败」,断言自动切换到 3457、config 被更新、代理以新端口启动(写法对齐既有的non_bosshunter_service用例)。设计决策
cdp-proxy.mjs:端口由 Python 侧统一编排,通过BOSSHUNTER_BROWSER_PROXY_PORT环境变量传入,Node 侧无需感知回退逻辑。测试与验证
tests/test_browser_runtime.py+tests/test_browser_diagnostics.py共 24 个全部通过(含新增用例)config.yaml的proxy_port临时设为 3456(当前系统保留段 3414-3513 内)→bosshunter connect自动回退到 3514,四项检测全绿:proxy_port: 8456(可绑定)→ 直接启动,无行为变化bosshunter --help正常运行