Skip to content

[BUG] start.bat/start.sh 端口冲突检测逻辑反转 + 变量提前引用 #56

@SonicBotMan

Description

@SonicBotMan

问题描述

发现 start.batstart.sh 中存在多个逻辑问题,其中端口冲突检测逻辑反转是最严重的。


Bug 1: 端口冲突检测逻辑反转(Critical)

文件: start.bat,约第 90-97 行

if !PORT_CONFLICT!==0 (
    echo.
    echo [WARN] Port conflicts detected!
    echo        1. Stop the processes using these ports
    echo        2. Or change port numbers in configuration
    echo.
    ...
)

问题: PORT_CONFLICT=0 表示没有冲突,但代码在 PORT_CONFLICT=0 时显示"冲突检测到"的警告。

修复: 改为 if !PORT_CONFLICT!==1


Bug 2: LLM_BUNDLED_READY 在定义前被引用

文件: start.bat 第 [0/6] 步(约第 80-95 行)

if exist "%LLM_BIN%" if exist "%LLM_MODEL%" (
    echo Checking port %LLM_PORT% (LLM)...
)

LLM_BINLLM_MODEL 都是在第 [3/6] 步才定义的。在第 [0/6] 步时这些变量为空。

同样的问题在 start.sh 的第 1.5/6 步中,$LLM_BUNDLED_READY 在引用时还未定义。

修复: 将 LLM 端口检测移到第 [3/6] 步之后,或在脚本开头预定义这些变量。


Bug 3: if errorlevel 0 逻辑错误

文件: start.bat 第 60 行

netstat -ano | findstr ":%GATEWAY_PORT%" | findstr "LISTENING" >nul 2>&1
if errorlevel 0 (
    echo [ERROR] Port %GATEWAY_PORT% is already in use
)

问题: CMD 中 if errorlevel 0 表示"errorlevel ≥ 0",永远为真。

修复: 改为 if not errorlevel 1if %errorlevel% equ 0


严重级

  • Bug 1: 🔴 Critical — 用户端口正常时被要求确认,有冲突时反而静默通过
  • Bug 2: 🟠 High — LLM 端口永远不会在启动前被检测
  • Bug 3: 🟠 High — 端口检测可能误报

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