From 34a411f3c0f1f7386969a141589b5ececd628151 Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Wed, 20 Dec 2023 13:59:31 -0500 Subject: [PATCH] add timeout in between data chunks --- .../internal/download/download-artifact.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/artifact/src/internal/download/download-artifact.ts b/packages/artifact/src/internal/download/download-artifact.ts index 0bc4a508..697a10c8 100644 --- a/packages/artifact/src/internal/download/download-artifact.ts +++ b/packages/artifact/src/internal/download/download-artifact.ts @@ -67,11 +67,30 @@ async function streamExtractInternal( return new Promise((resolve, reject) => { const zipStream = unzip.Extract({path: directory}) + + const timeout = 30 * 1000 + const timerFn = (): void => { + throw new Error(`Blob storage chunk did not respond in ${timeout}ms `) + } + let timer = setTimeout(timerFn, timeout) + try { - response.message.pipe(zipStream).on('close', resolve).on('error', reject) + response.message + .on('data', () => { + clearTimeout(timer) + timer = setTimeout(timerFn, timeout) + }) + .pipe(zipStream) + .on('close', () => { + clearTimeout(timer) + resolve() + }) + .on('error', reject) } catch (error) { zipStream.end() reject(error) + } finally { + clearTimeout(timer) } }) }