From 446bdb1f46904c892ece0ba458b004a23dc0708c Mon Sep 17 00:00:00 2001 From: zhom <2717306+zhom@users.noreply.github.com> Date: Sat, 25 Apr 2026 17:55:31 +0400 Subject: [PATCH] chore: tests --- scripts/sync-test-harness.mjs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/sync-test-harness.mjs b/scripts/sync-test-harness.mjs index 4bdb834..cd252d0 100755 --- a/scripts/sync-test-harness.mjs +++ b/scripts/sync-test-harness.mjs @@ -48,6 +48,7 @@ async function downloadFile(url, dest) { protocol .get(url, (response) => { if (response.statusCode === 302 || response.statusCode === 301) { + file.close(); downloadFile(response.headers.location, dest) .then(resolve) .catch(reject); @@ -55,11 +56,28 @@ async function downloadFile(url, dest) { } if (response.statusCode !== 200) { + file.close(); reject(new Error(`Failed to download: ${response.statusCode}`)); return; } - pipeline(response, file).then(resolve).catch(reject); + // pipeline() resolves once the source ends but doesn't await the + // destination fd closing. Linux refuses to exec a file whose write + // fd is still open (ETXTBSY), so explicitly wait for 'close'. + pipeline(response, file) + .then( + () => + new Promise((res, rej) => { + if (file.closed) { + res(); + } else { + file.once("close", res); + file.once("error", rej); + } + }), + ) + .then(resolve) + .catch(reject); }) .on("error", reject); });