fix(node-agent): await async cleanup + fix syntax
This commit is contained in:
parent
315b31a68b
commit
21ba7595b3
1 changed files with 14 additions and 14 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue