diff --git a/services/mam-api/src/routes/recorders.js b/services/mam-api/src/routes/recorders.js index f5fe77f..d44f4cc 100644 --- a/services/mam-api/src/routes/recorders.js +++ b/services/mam-api/src/routes/recorders.js @@ -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`, {