@@ -5657,20 +5657,24 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
56575657 const fd = fs.openSync(archivePath, 'w');
56585658 try {
56595659 downloadProgress.startDisplayTimer();
5660- const abortSignal = abort_controller_1.AbortController.timeout(options.segmentTimeoutInMs || 3600000);
5661- abortSignal.addEventListener('abort', () => {
5662- core.warning('Aborting cache download as it exceeded the timeout.');
5663- });
5660+ const controller = new abort_controller_1.AbortController();
5661+ const abortSignal = controller.signal;
56645662 while (!downloadProgress.isDone()) {
56655663 const segmentStart = downloadProgress.segmentOffset + downloadProgress.segmentSize;
56665664 const segmentSize = Math.min(maxSegmentSize, contentLength - segmentStart);
56675665 downloadProgress.nextSegment(segmentSize);
5668- const result = yield client.downloadToBuffer(segmentStart, segmentSize, {
5666+ const result = yield promiseWithTimeout(options.segmentTimeoutInMs || 3600000, client.downloadToBuffer(segmentStart, segmentSize, {
56695667 abortSignal,
56705668 concurrency: options.downloadConcurrency,
56715669 onProgress: downloadProgress.onProgress()
5672- });
5673- fs.writeFileSync(fd, result);
5670+ }));
5671+ if (result === 'timeout') {
5672+ controller.abort();
5673+ throw new Error('Aborting cache download as the download time exceeded the timeout.');
5674+ }
5675+ else if (Buffer.isBuffer(result)) {
5676+ fs.writeFileSync(fd, result);
5677+ }
56745678 }
56755679 }
56765680 finally {
@@ -5681,6 +5685,16 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
56815685 });
56825686}
56835687exports.downloadCacheStorageSDK = downloadCacheStorageSDK;
5688+ const promiseWithTimeout = (timeoutMs, promise) => __awaiter(void 0, void 0, void 0, function* () {
5689+ let timeoutHandle;
5690+ const timeoutPromise = new Promise(resolve => {
5691+ timeoutHandle = setTimeout(() => resolve('timeout'), timeoutMs);
5692+ });
5693+ return Promise.race([promise, timeoutPromise]).then(result => {
5694+ clearTimeout(timeoutHandle);
5695+ return result;
5696+ });
5697+ });
56845698//# sourceMappingURL=downloadUtils.js.map
56855699
56865700/***/ }),
0 commit comments