From 73b52181f7c75fcc8e081747fa7d48d2fd052519 Mon Sep 17 00:00:00 2001 From: Bishal Prasad Date: Fri, 29 Jul 2022 12:37:50 +0530 Subject: [PATCH] Hack for timeout for segment download --- src/internal/downloadUtils.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index 08b2dee..6c3cf38 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -6,6 +6,7 @@ import * as buffer from 'buffer' import * as fs from 'fs' import * as stream from 'stream' import * as util from 'util' +import * as timer from 'timers/promises' import * as utils from './cacheUtils' import {SocketTimeout} from './constants' @@ -259,14 +260,19 @@ export async function downloadCacheStorageSDK( downloadProgress.nextSegment(segmentSize) - const result = await client.downloadToBuffer( - segmentStart, - segmentSize, - { - concurrency: options.downloadConcurrency, - onProgress: downloadProgress.onProgress() - } - ) + const result = await Promise.Race([client.downloadToBuffer( + segmentStart, + segmentSize, + { + concurrency: options.downloadConcurrency, + onProgress: downloadProgress.onProgress() + } + ), + timer.setTimeout(60 * 60 * 1000, 'timeout')]); + + if(result === 'timeout') { + throw new Error("Segment download timed out"); + } fs.writeFileSync(fd, result) }