fix: add retry limit to startup wait loops to prevent infinite hang
Each service wait loop now fails after 30 retries (~60s) instead of spinning forever when a port is occupied by a stuck process. Also added cleanup label that kills partially-started services on failure.
This commit is contained in:
@@ -29,10 +29,21 @@ start "jrxml-validator" /MIN .venv\Scripts\python.exe -c "import uvicorn; uvicor
|
||||
|
||||
:: 等待验证服务就绪 (用 PowerShell 检测)
|
||||
echo [等待] 验证服务就绪...
|
||||
set /a RETRY=0
|
||||
:wait_val
|
||||
ping -n 2 127.0.0.1 >nul
|
||||
powershell -Command "try{$r=Invoke-WebRequest -Uri http://localhost:8001/health -TimeoutSec 2 -UseBasicParsing;exit 0}catch{exit 1}" >nul 2>&1
|
||||
if errorlevel 1 goto wait_val
|
||||
if not errorlevel 1 goto val_ok
|
||||
set /a RETRY+=1
|
||||
if %RETRY% GEQ 30 (
|
||||
echo [失败] 验证服务启动超时,请检查端口 8001 是否被占用
|
||||
taskkill /F /FI "WINDOWTITLE eq jrxml-validator*" >nul 2>&1
|
||||
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":8001.*LISTENING"') do taskkill /F /PID %%a >nul 2>&1
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
goto wait_val
|
||||
:val_ok
|
||||
echo :8001 就绪
|
||||
|
||||
:: 启动 API 服务 (前台,Ctrl+C 退出)
|
||||
|
||||
Reference in New Issue
Block a user