fix: improve gateway PID recovery and port detection (#660)

- Refactor port detection into reusable getListeningPids/killListeningPids
- Add ss command fallback when lsof is unavailable
- Extract readPidFile for cleaner PID file reading
- Remove unnecessary PowerShell candidate from Windows shell detection
- Add PID validity check in gateway_state.json fallback (Number.isFinite + > 0)

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
ekko
2026-05-12 20:53:21 +08:00
committed by GitHub
parent c987448f01
commit 8b57c4a278
2 changed files with 48 additions and 35 deletions
@@ -221,7 +221,7 @@ export class GatewayManager {
const data = JSON.parse(content)
const pid = typeof data.pid === 'number' ? data.pid : parseInt(data.pid, 10) || null
const state = data?.gateway_state
return pid && (state === 'running' || state === 'starting') ? pid : null
return pid && Number.isFinite(pid) && pid > 0 && (state === 'running' || state === 'starting') ? pid : null
} catch {
return null
}