Add port-in-use detection to start scripts with helpful error message
enhancement
## Summary
When starting the app with `./app/start.sh` or `./app/start.ps1`, if the target port is already in use (e.g. another worktree's backend is running), quart fails with a generic `OSError: [Errno 48] Address already in use`. The error doesn't tell the developer how to fix it.
## Motivation
When working in multiple git worktrees of this repo simultaneously, the second instance collides on port 50505. After #3116 made the port configurable via `PORT` env var, the scripts should detect the conflict early and tell the developer exactly what to do.
## Proposed change
Add a pre-flight port check in both start scripts before launching quart:
**start.sh:**
```sh
if lsof -i :"$port" -sTCP:LISTEN >/dev/null 2>&1; then
echo "Port $port is already in use. Set PORT=<number> to use a different port."
exit 1
fi
```
**start.ps1:**
```powershell
if (Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue) {
Write-Host "Port $port is already in use. Set env:PORT to use a different port."
exit 1
}
```
## Acceptance criteria
- If the port is free, scripts behave exactly as today.
- If the port is occupied, the script exits immediately with a clear message telling the user to set `PORT` to a different value.
关闭于 2026-06-25 0 条评论