From 21ba7595b30fb4e555d67889c72d4678751cd342 Mon Sep 17 00:00:00 2001 From: Wild Dragon Dev Date: Thu, 4 Jun 2026 00:57:22 +0000 Subject: [PATCH] fix(node-agent): await async cleanup + fix syntax --- services/node-agent/index.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/services/node-agent/index.js b/services/node-agent/index.js index 6bf4dbd..958a248 100644 --- a/services/node-agent/index.js +++ b/services/node-agent/index.js @@ -611,12 +611,12 @@ async function handleSidecarStart(body, res) { hostConfig.IpcMode = 'host'; } - // Single cleanup for ALL failure paths (create fail, start fail, throw): + // Single cleanup for ALL failure paths (create fail, start fail, throw): // decrements the right bridge counter (stopping the bridge when it hits 0) // AND stops any net_ingest started for this request. Previously only the // deltacast counter was decremented — blackmagic count and net_ingest leaked // on every failed start, eventually stranding the bridge / ingest forever. - const _cleanupOnFailure = () => { + const _cleanupOnFailure = async () => { if (sourceType === 'deltacast') { _dcSidecarCount--; if (_dcSidecarCount <= 0) { _dcSidecarCount = 0; stopDeltacastBridge(); } @@ -632,12 +632,12 @@ async function handleSidecarStart(body, res) { }; let containerId; - try { - const createRes = await dockerApi('POST', '/containers/create', spec); - if (createRes.status !== 201) { - _cleanupOnFailure(); - return jsonResponse(res, 502, { error: 'Failed to create container', details: createRes.data }); - } + try { + const createRes = await dockerApi('POST', '/containers/create', spec); + if (createRes.status !== 201) { + await _cleanupOnFailure(); + return jsonResponse(res, 502, { error: 'Failed to create container', details: createRes.data }); + } containerId = createRes.data.Id; const _u = (env.find(e => e.startsWith('MAM_API_URL=')) || '').slice(12); @@ -646,7 +646,7 @@ async function handleSidecarStart(body, res) { const startRes = await dockerApi('POST', `/containers/${containerId}/start`); if (startRes.status !== 204) { await dockerApi('DELETE', `/containers/${containerId}?force=true`).catch(() => {}); - _cleanupOnFailure(); + await _cleanupOnFailure(); return jsonResponse(res, 502, { error: 'Failed to start container', details: startRes.data }); } @@ -663,7 +663,7 @@ async function handleSidecarStart(body, res) { } jsonResponse(res, 201, { containerId, capturePort }); } catch (err) { - _cleanupOnFailure(); + await _cleanupOnFailure(); throw err; } } catch (err) { @@ -774,7 +774,7 @@ async function handleSidecarStandby(body, res) { hostConfig.IpcMode = 'host'; } - const _cleanupOnFailure = () => { + const _cleanupOnFailure = async () => { if (sourceType === 'deltacast') { _dcSidecarCount--; if (_dcSidecarCount <= 0) { _dcSidecarCount = 0; stopDeltacastBridge(); } @@ -788,7 +788,7 @@ async function handleSidecarStandby(body, res) { try { const createRes = await dockerApi('POST', '/containers/create', { Image: image, Env: sidecarEnv, HostConfig: hostConfig }); if (createRes.status !== 201) { - _cleanupOnFailure(); + await _cleanupOnFailure(); return jsonResponse(res, 502, { error: 'Failed to create standby container', details: createRes.data }); } containerId = createRes.data.Id; @@ -796,14 +796,14 @@ async function handleSidecarStandby(body, res) { const startRes = await dockerApi('POST', `/containers/${containerId}/start`); if (startRes.status !== 204) { await dockerApi('DELETE', `/containers/${containerId}?force=true`).catch(() => {}); - _cleanupOnFailure(); + await _cleanupOnFailure(); return jsonResponse(res, 502, { error: 'Failed to start standby container', details: startRes.data }); } if (sourceType === 'deltacast') _containerSourceType.set(containerId, 'deltacast'); if (sourceType === 'sdi' || sourceType === 'blackmagic') _containerSourceType.set(containerId, 'blackmagic'); jsonResponse(res, 201, { containerId, capturePort }); } catch (err) { - _cleanupOnFailure(); + await _cleanupOnFailure(); throw err; } } catch (err) {