Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ async function decodeOnce(filePath, timeoutMs) {
}

/**
* Full-stream decode. Retries once on timeout/IO errors (flaky disk, sleeping drive)
* Full-stream decode. Retries once on timeout/IO errors with a doubled timeout
* before declaring failure; such retries are NOT corruption evidence.
* Result.timeout === true means "inconclusive (timed out)", never "corrupt".
*/
export async function fullDecode(filePath, { timeoutMs = 120000, retryIoOnce = true } = {}) {
try {
Expand All @@ -37,12 +38,14 @@ export async function fullDecode(filePath, { timeoutMs = 120000, retryIoOnce = t
return { pass: false, error: `File not found or unreadable: ${err.message}`, retried: false };
}
const first = await decodeOnce(filePath, timeoutMs);
if (first.pass) return { pass: true, error: null, retried: false };
if (first.pass) return { pass: true, error: null, retried: false, timeout: false };
if (retryIoOnce && first.ioTimeout) {
const second = await decodeOnce(filePath, timeoutMs);
return { pass: second.pass, error: second.error, retried: true };
// Retry with a doubled timeout: slow CPU + large files is the common
// cause, and a timeout is NOT corruption evidence (Taskmaster S22E03).
const second = await decodeOnce(filePath, timeoutMs * 2);
return { pass: second.pass, error: second.error, retried: true, timeout: !second.pass && !!second.ioTimeout };
}
return { pass: false, error: first.error, retried: false };
return { pass: false, error: first.error, retried: false, timeout: !!first.ioTimeout };
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/remediation.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ async function tickVerifying(rem) {
setRemediationState(rem.episode_id, 'importing', { details: `verified ${record.outputPath}` });
return;
}
if (decoded.timeout) {
console.error('[remediation] replacement decode timed out - inconclusive, retrying next tick:', rem.episode_id);
return; // stay verifying; attempts untouched; verifying time bound still protects
}
try { await deleteQueueItem(record.id, { removeFromClient: true, blocklist: true }); } catch {}
await attemptFailed(rem, `replacement decode failed: ${decoded.error}`);
}
Expand Down Expand Up @@ -173,6 +177,10 @@ async function tickImporting(rem) {
await waitForStableFile(local, { intervalMs: 5000, checks: 2, maxWaitMs: 120000 });
} catch { return; }
const decoded = await fullDecode(local, { timeoutMs: 900000 });
if (decoded.timeout) {
console.error('[remediation] post-import decode timed out - inconclusive, re-verifying next tick:', rem.episode_id);
return; // stay importing; re-verify on next tick
}
if (decoded.pass) {
setRemediationState(rem.episode_id, 'swapped', { details: 'replacement verified on disk' });
logAction(rem, 'remediation_swapped', 'Replacement downloaded, verified clean, and imported. Old corrupt file replaced.');
Expand Down
12 changes: 12 additions & 0 deletions src/sonarr.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ export async function ensureUpcomingEpisodes(seriesId, season, episode, preloade
});
continue;
}
if (confirm.timeout) {
// Decode timed out (CPU contention on large files) - NOT evidence of
// corruption. Skip remediation; the file is re-probed on a later trigger.
actions.push({
episodeId: ep.id,
season: ep.seasonNumber,
episode: ep.episodeNumber,
action: 'integrity_probe_inconclusive',
details: 'Confirm decode timed out (not corruption evidence) - will re-verify next trigger',
});
continue;
}
clearVerifiedFile(ep.episodeFileId);
const { startRemediation } = await import('./remediation.js');
const row = await startRemediation({
Expand Down
10 changes: 10 additions & 0 deletions tests/decoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ test('isIoTimeoutError matches timeout and EIO, not generic errors', () => {
assert.equal(isIoTimeoutError(new Error('EIO: i/o error')), true);
assert.equal(isIoTimeoutError(new Error('something else')), false);
});

test('fullDecode marks timeout as inconclusive (never corruption) and doubles retry timeout', async () => {
const file = makeMedia(tmpDir(), 'slow.mp4');
// 1ms is far below real decode time -> first attempt killed by timeout;
// retry gets the doubled timeout (2ms), still killed -> inconclusive.
const r = await fullDecode(file, { timeoutMs: 1 });
assert.equal(r.pass, false);
assert.equal(r.timeout, true);
assert.equal(r.retried, true);
});
Loading