fix(recorders): kill stale standby container before on-demand respawn to prevent EADDRINUSE

This commit is contained in:
Wild Dragon Dev 2026-06-03 23:04:17 +00:00
parent a096226072
commit a5aed86349

View file

@ -801,6 +801,23 @@ router.post('/:id/start', requireRecorderEdit, async (req, res, next) => {
}
}
// If standby HTTP start failed and a stale container_id exists, kill it
// before spawning a new one — otherwise the new container gets EADDRINUSE
// because the old container is still holding the capture port.
if (!containerId && isStandby && recorder.container_id) {
console.log(`[recorders] killing stale standby container ${recorder.container_id} before respawn`);
try {
if (isRemote) {
await fetch(`${targetNodeApiUrl}/sidecar/${recorder.container_id}`, {
method: 'DELETE',
signal: AbortSignal.timeout(10000),
}).catch(() => {});
} else {
await dockerApi('DELETE', `/containers/${recorder.container_id}?force=true`).catch(() => {});
}
} catch (_) {}
}
if (!containerId && isRemote) {
// Remote node: delegate container lifecycle to that node's agent.
const sidecarRes = await fetch(`${targetNodeApiUrl}/sidecar/start`, {