From 73b52181f7c75fcc8e081747fa7d48d2fd052519 Mon Sep 17 00:00:00 2001 From: Bishal Prasad Date: Fri, 29 Jul 2022 12:37:50 +0530 Subject: [PATCH 01/13] 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) } From f7739db321684d946c58dc730a5b7b74125d06f9 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari <64764738+tiwarishub@users.noreply.github.com> Date: Fri, 29 Jul 2022 12:52:57 +0530 Subject: [PATCH 02/13] Update downloadUtils.ts --- src/internal/downloadUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index 6c3cf38..9cde1f4 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -260,7 +260,7 @@ export async function downloadCacheStorageSDK( downloadProgress.nextSegment(segmentSize) - const result = await Promise.Race([client.downloadToBuffer( + const result = await Promise.race([client.downloadToBuffer( segmentStart, segmentSize, { From 4e2d0885c4a40a93e688c962078b0492b30e420a Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Wed, 3 Aug 2022 10:23:42 +0000 Subject: [PATCH 03/13] Added abortController to stop download --- src/internal/downloadUtils.ts | 11 ++++++++--- src/options.ts | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index 9cde1f4..af2a46f 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -13,6 +13,8 @@ import {SocketTimeout} from './constants' import {DownloadOptions} from '../options' import {retryHttpClientResponse} from './requestUtils' +import { AbortController } from "@azure/abort-controller"; + /** * Pipes the body of a HTTP response to a stream * @@ -248,7 +250,8 @@ export async function downloadCacheStorageSDK( try { downloadProgress.startDisplayTimer() - + const controller = new AbortController(); + const abortSignal = controller.signal; while (!downloadProgress.isDone()) { const segmentStart = downloadProgress.segmentOffset + downloadProgress.segmentSize @@ -264,14 +267,16 @@ export async function downloadCacheStorageSDK( segmentStart, segmentSize, { + abortSignal: abortSignal, concurrency: options.downloadConcurrency, onProgress: downloadProgress.onProgress() } ), - timer.setTimeout(60 * 60 * 1000, 'timeout')]); + timer.setTimeout(options.abortTimeInMs, 'timeout')]); if(result === 'timeout') { - throw new Error("Segment download timed out"); + controller.abort(); + throw new Error("Download aborted, segment download timed out."); } fs.writeFileSync(fd, result) diff --git a/src/options.ts b/src/options.ts index 94642fd..bc0c03b 100644 --- a/src/options.ts +++ b/src/options.ts @@ -45,7 +45,16 @@ export interface DownloadOptions { * * @default 30000 */ - timeoutInMs?: number + timeoutInMs?: number + + + /** + * Time after which download should be aborted if stuck + * + * @default 2700000 + */ + abortTimeInMs?: number + } /** @@ -84,7 +93,8 @@ export function getDownloadOptions(copy?: DownloadOptions): DownloadOptions { const result: DownloadOptions = { useAzureSdk: true, downloadConcurrency: 8, - timeoutInMs: 30000 + timeoutInMs: 30000, + abortTimeInMs: 2700000 } if (copy) { @@ -99,11 +109,16 @@ export function getDownloadOptions(copy?: DownloadOptions): DownloadOptions { if (typeof copy.timeoutInMs === 'number') { result.timeoutInMs = copy.timeoutInMs } + + if (typeof copy.abortTimeInMs === 'number') { + result.abortTimeInMs = copy.abortTimeInMs + } } core.debug(`Use Azure SDK: ${result.useAzureSdk}`) core.debug(`Download concurrency: ${result.downloadConcurrency}`) core.debug(`Request timeout (ms): ${result.timeoutInMs}`) + core.debug(`Abort time (ms): ${result.abortTimeInMs}`) return result } From 3c8d7fb1c3f2a2f943ebd305271a1bb60e3af3b0 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Wed, 3 Aug 2022 11:11:30 +0000 Subject: [PATCH 04/13] Added abort controller for timer --- src/internal/downloadUtils.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index af2a46f..1c0950c 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -251,6 +251,7 @@ export async function downloadCacheStorageSDK( try { downloadProgress.startDisplayTimer() const controller = new AbortController(); + const timerController = new AbortController(); const abortSignal = controller.signal; while (!downloadProgress.isDone()) { const segmentStart = @@ -262,7 +263,6 @@ export async function downloadCacheStorageSDK( ) downloadProgress.nextSegment(segmentSize) - const result = await Promise.race([client.downloadToBuffer( segmentStart, segmentSize, @@ -272,11 +272,14 @@ export async function downloadCacheStorageSDK( onProgress: downloadProgress.onProgress() } ), - timer.setTimeout(options.abortTimeInMs, 'timeout')]); + timer.setTimeout(options.abortTimeInMs, 'timeout',{ signal: timerController.signal })]); if(result === 'timeout') { controller.abort(); throw new Error("Download aborted, segment download timed out."); + } else { + timerController.abort(); + core.debug("Download completely successfully, cancelling timer.") } fs.writeFileSync(fd, result) From 3e991a3fe9cc5db594392d1472e34bfb8ce35986 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Wed, 3 Aug 2022 13:25:47 +0000 Subject: [PATCH 05/13] Added custom promise with timeout --- __tests__/options.test.ts | 7 +++++-- src/internal/downloadUtils.ts | 39 ++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/__tests__/options.test.ts b/__tests__/options.test.ts index 3075b43..94b0e0e 100644 --- a/__tests__/options.test.ts +++ b/__tests__/options.test.ts @@ -8,6 +8,7 @@ import { const useAzureSdk = true const downloadConcurrency = 8 const timeoutInMs = 30000 +const abortTimeInMs = 2700000 const uploadConcurrency = 4 const uploadChunkSize = 32 * 1024 * 1024 @@ -17,7 +18,8 @@ test('getDownloadOptions sets defaults', async () => { expect(actualOptions).toEqual({ useAzureSdk, downloadConcurrency, - timeoutInMs + timeoutInMs, + abortTimeInMs }) }) @@ -25,7 +27,8 @@ test('getDownloadOptions overrides all settings', async () => { const expectedOptions: DownloadOptions = { useAzureSdk: false, downloadConcurrency: 14, - timeoutInMs: 20000 + timeoutInMs: 20000, + abortTimeInMs: 2700000 } const actualOptions = getDownloadOptions(expectedOptions) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index 1c0950c..cccf2c0 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -6,7 +6,6 @@ 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' @@ -251,7 +250,6 @@ export async function downloadCacheStorageSDK( try { downloadProgress.startDisplayTimer() const controller = new AbortController(); - const timerController = new AbortController(); const abortSignal = controller.signal; while (!downloadProgress.isDone()) { const segmentStart = @@ -263,22 +261,20 @@ export async function downloadCacheStorageSDK( ) downloadProgress.nextSegment(segmentSize) - const result = await Promise.race([client.downloadToBuffer( - segmentStart, - segmentSize, - { - abortSignal: abortSignal, - concurrency: options.downloadConcurrency, - onProgress: downloadProgress.onProgress() - } - ), - timer.setTimeout(options.abortTimeInMs, 'timeout',{ signal: timerController.signal })]); - + const abortTimeInMs = options.abortTimeInMs == undefined ? 2700000 : options.abortTimeInMs; + const result = await promiseWithTimeout(abortTimeInMs, client.downloadToBuffer( + segmentStart, + segmentSize, + { + abortSignal: abortSignal, + concurrency: options.downloadConcurrency, + onProgress: downloadProgress.onProgress() + } + )); if(result === 'timeout') { controller.abort(); throw new Error("Download aborted, segment download timed out."); } else { - timerController.abort(); core.debug("Download completely successfully, cancelling timer.") } @@ -290,3 +286,18 @@ export async function downloadCacheStorageSDK( } } } + +const promiseWithTimeout = (timeoutMs: number, promise: Promise) => { + let timeoutHandle: NodeJS.Timeout; + const timeoutPromise = new Promise((resolve, reject) => { + timeoutHandle = setTimeout(() => resolve('timeout'), timeoutMs); + }); + + return Promise.race([ + promise, + timeoutPromise, + ]).then((result) => { + clearTimeout(timeoutHandle); + return result; + }); +} \ No newline at end of file From 55fef07ca0cf3aefdcd200f3031de4ca6cdfcf6f Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Wed, 3 Aug 2022 14:12:16 +0000 Subject: [PATCH 06/13] Linting fixes --- src/internal/downloadUtils.ts | 59 +++++++++++++++++------------------ src/options.ts | 6 ++-- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index cccf2c0..992ca78 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -12,7 +12,7 @@ import {SocketTimeout} from './constants' import {DownloadOptions} from '../options' import {retryHttpClientResponse} from './requestUtils' -import { AbortController } from "@azure/abort-controller"; +import {AbortController} from '@azure/abort-controller' /** * Pipes the body of a HTTP response to a stream @@ -249,8 +249,7 @@ export async function downloadCacheStorageSDK( try { downloadProgress.startDisplayTimer() - const controller = new AbortController(); - const abortSignal = controller.signal; + const controller = new AbortController() while (!downloadProgress.isDone()) { const segmentStart = downloadProgress.segmentOffset + downloadProgress.segmentSize @@ -261,24 +260,22 @@ export async function downloadCacheStorageSDK( ) downloadProgress.nextSegment(segmentSize) - const abortTimeInMs = options.abortTimeInMs == undefined ? 2700000 : options.abortTimeInMs; - const result = await promiseWithTimeout(abortTimeInMs, client.downloadToBuffer( - segmentStart, - segmentSize, - { - abortSignal: abortSignal, + const abortTimeInMs = + options.abortTimeInMs === undefined ? 2700000 : options.abortTimeInMs + const result = await promiseWithTimeout( + abortTimeInMs, + client.downloadToBuffer(segmentStart, segmentSize, { + abortSignal: controller.signal, concurrency: options.downloadConcurrency, onProgress: downloadProgress.onProgress() - } - )); - if(result === 'timeout') { - controller.abort(); - throw new Error("Download aborted, segment download timed out."); - } else { - core.debug("Download completely successfully, cancelling timer.") + }) + ) + if (result === 'timeout') { + controller.abort() + throw new Error('Download aborted, segment download timed out.') + } else if (Buffer.isBuffer(result)) { + fs.writeFileSync(fd, result) } - - fs.writeFileSync(fd, result) } } finally { downloadProgress.stopDisplayTimer() @@ -287,17 +284,17 @@ export async function downloadCacheStorageSDK( } } -const promiseWithTimeout = (timeoutMs: number, promise: Promise) => { - let timeoutHandle: NodeJS.Timeout; - const timeoutPromise = new Promise((resolve, reject) => { - timeoutHandle = setTimeout(() => resolve('timeout'), timeoutMs); - }); +const promiseWithTimeout = async ( + timeoutMs: number, + promise: Promise +): Promise => { + let timeoutHandle: NodeJS.Timeout + const timeoutPromise = new Promise(resolve => { + timeoutHandle = setTimeout(() => resolve('timeout'), timeoutMs) + }) - return Promise.race([ - promise, - timeoutPromise, - ]).then((result) => { - clearTimeout(timeoutHandle); - return result; - }); -} \ No newline at end of file + return Promise.race([promise, timeoutPromise]).then(result => { + clearTimeout(timeoutHandle) + return result + }) +} diff --git a/src/options.ts b/src/options.ts index bc0c03b..7473cfe 100644 --- a/src/options.ts +++ b/src/options.ts @@ -45,16 +45,14 @@ export interface DownloadOptions { * * @default 30000 */ - timeoutInMs?: number + timeoutInMs?: number - /** * Time after which download should be aborted if stuck * * @default 2700000 */ - abortTimeInMs?: number - + abortTimeInMs?: number } /** From 5591252081317782f4657ecd365b5ceac4acb4af Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Fri, 5 Aug 2022 05:44:59 +0000 Subject: [PATCH 07/13] Updated 45 mins abort timeout to 1 hour --- __tests__/options.test.ts | 4 ++-- src/internal/downloadUtils.ts | 2 +- src/options.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/options.test.ts b/__tests__/options.test.ts index 94b0e0e..6b3e0c2 100644 --- a/__tests__/options.test.ts +++ b/__tests__/options.test.ts @@ -8,7 +8,7 @@ import { const useAzureSdk = true const downloadConcurrency = 8 const timeoutInMs = 30000 -const abortTimeInMs = 2700000 +const abortTimeInMs = 3600000 const uploadConcurrency = 4 const uploadChunkSize = 32 * 1024 * 1024 @@ -28,7 +28,7 @@ test('getDownloadOptions overrides all settings', async () => { useAzureSdk: false, downloadConcurrency: 14, timeoutInMs: 20000, - abortTimeInMs: 2700000 + abortTimeInMs: 3600000 } const actualOptions = getDownloadOptions(expectedOptions) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index 992ca78..e4f421f 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -261,7 +261,7 @@ export async function downloadCacheStorageSDK( downloadProgress.nextSegment(segmentSize) const abortTimeInMs = - options.abortTimeInMs === undefined ? 2700000 : options.abortTimeInMs + options.abortTimeInMs === undefined ? 3600000 : options.abortTimeInMs const result = await promiseWithTimeout( abortTimeInMs, client.downloadToBuffer(segmentStart, segmentSize, { diff --git a/src/options.ts b/src/options.ts index 7473cfe..b556326 100644 --- a/src/options.ts +++ b/src/options.ts @@ -50,7 +50,7 @@ export interface DownloadOptions { /** * Time after which download should be aborted if stuck * - * @default 2700000 + * @default 3600000 */ abortTimeInMs?: number } @@ -92,7 +92,7 @@ export function getDownloadOptions(copy?: DownloadOptions): DownloadOptions { useAzureSdk: true, downloadConcurrency: 8, timeoutInMs: 30000, - abortTimeInMs: 2700000 + abortTimeInMs: 3600000 } if (copy) { From 736ee61ac82ee28a60b80ad1a221982abaabf5a2 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Fri, 5 Aug 2022 07:20:59 +0000 Subject: [PATCH 08/13] Updated version and Releases.md --- RELEASES.md | 5 ++++- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 931228a..34bbace 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -74,4 +74,7 @@ ### 3.0.1 - Fix [#833](https://github.com/actions/cache/issues/833) - cache doesn't work with github workspace directory. -- Fix [#809](https://github.com/actions/cache/issues/809) `zstd -d: no such file or directory` error on AWS self-hosted runners. \ No newline at end of file +- Fix [#809](https://github.com/actions/cache/issues/809) `zstd -d: no such file or directory` error on AWS self-hosted runners. + +### 3.0.2 +- Added 1 hour timeout for the download stuck issue [#810](https://github.com/actions/cache/issues/810). \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index de8c7e0..05de404 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@actions/cache", - "version": "3.0.1", + "version": "3.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@actions/cache", - "version": "3.0.1", + "version": "3.0.2", "license": "MIT", "dependencies": { "@actions/core": "^1.2.6", diff --git a/package.json b/package.json index 19d065b..26b02f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@actions/cache", - "version": "3.0.1", + "version": "3.0.2", "preview": true, "description": "Actions cache lib", "keywords": [ From 3528ea98d1a3669a369da425e1b8997e5e701f04 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Fri, 5 Aug 2022 11:09:23 +0000 Subject: [PATCH 09/13] Removed custom promise and used abort timeout --- src/internal/downloadUtils.ts | 44 ++++++++++++----------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index e4f421f..adaf739 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -249,7 +249,12 @@ export async function downloadCacheStorageSDK( try { downloadProgress.startDisplayTimer() - const controller = new AbortController() + const abortTimeInMs = + options.abortTimeInMs === undefined ? 3600000 : options.abortTimeInMs + const abortSignal = AbortController.timeout(abortTimeInMs) + abortSignal.addEventListener('abort', () => { + core.warning("Cache download aborted, segment download timed out.") + }) while (!downloadProgress.isDone()) { const segmentStart = downloadProgress.segmentOffset + downloadProgress.segmentSize @@ -260,22 +265,18 @@ export async function downloadCacheStorageSDK( ) downloadProgress.nextSegment(segmentSize) - const abortTimeInMs = - options.abortTimeInMs === undefined ? 3600000 : options.abortTimeInMs - const result = await promiseWithTimeout( - abortTimeInMs, - client.downloadToBuffer(segmentStart, segmentSize, { - abortSignal: controller.signal, + + const result = await client.downloadToBuffer( + segmentStart, + segmentSize, + { + abortSignal: abortSignal, concurrency: options.downloadConcurrency, onProgress: downloadProgress.onProgress() - }) + } ) - if (result === 'timeout') { - controller.abort() - throw new Error('Download aborted, segment download timed out.') - } else if (Buffer.isBuffer(result)) { - fs.writeFileSync(fd, result) - } + + fs.writeFileSync(fd, result) } } finally { downloadProgress.stopDisplayTimer() @@ -283,18 +284,3 @@ export async function downloadCacheStorageSDK( } } } - -const promiseWithTimeout = async ( - timeoutMs: number, - promise: Promise -): Promise => { - let timeoutHandle: NodeJS.Timeout - const timeoutPromise = new Promise(resolve => { - timeoutHandle = setTimeout(() => resolve('timeout'), timeoutMs) - }) - - return Promise.race([promise, timeoutPromise]).then(result => { - clearTimeout(timeoutHandle) - return result - }) -} From edd4bb18a11d1b95ed41cf968661de20c63c63d6 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Fri, 5 Aug 2022 11:43:31 +0000 Subject: [PATCH 10/13] Fixed linting issues --- src/internal/downloadUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index adaf739..7852165 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -253,7 +253,7 @@ export async function downloadCacheStorageSDK( options.abortTimeInMs === undefined ? 3600000 : options.abortTimeInMs const abortSignal = AbortController.timeout(abortTimeInMs) abortSignal.addEventListener('abort', () => { - core.warning("Cache download aborted, segment download timed out.") + core.warning('Cache download aborted, segment download timed out.') }) while (!downloadProgress.isDone()) { const segmentStart = @@ -270,7 +270,7 @@ export async function downloadCacheStorageSDK( segmentStart, segmentSize, { - abortSignal: abortSignal, + abortSignal, concurrency: options.downloadConcurrency, onProgress: downloadProgress.onProgress() } From 47dad3f6761f24337347b35a29ec7d2d04b854e4 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 8 Aug 2022 04:48:36 +0000 Subject: [PATCH 11/13] Updated variable names --- __tests__/options.test.ts | 6 +++--- src/internal/downloadUtils.ts | 6 +++--- src/options.ts | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/__tests__/options.test.ts b/__tests__/options.test.ts index 6b3e0c2..5ec7b14 100644 --- a/__tests__/options.test.ts +++ b/__tests__/options.test.ts @@ -8,7 +8,7 @@ import { const useAzureSdk = true const downloadConcurrency = 8 const timeoutInMs = 30000 -const abortTimeInMs = 3600000 +const segmentTimeoutInMs = 3600000 const uploadConcurrency = 4 const uploadChunkSize = 32 * 1024 * 1024 @@ -19,7 +19,7 @@ test('getDownloadOptions sets defaults', async () => { useAzureSdk, downloadConcurrency, timeoutInMs, - abortTimeInMs + segmentTimeoutInMs }) }) @@ -28,7 +28,7 @@ test('getDownloadOptions overrides all settings', async () => { useAzureSdk: false, downloadConcurrency: 14, timeoutInMs: 20000, - abortTimeInMs: 3600000 + segmentTimeoutInMs: 3600000 } const actualOptions = getDownloadOptions(expectedOptions) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index 7852165..e93a93f 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -249,9 +249,9 @@ export async function downloadCacheStorageSDK( try { downloadProgress.startDisplayTimer() - const abortTimeInMs = - options.abortTimeInMs === undefined ? 3600000 : options.abortTimeInMs - const abortSignal = AbortController.timeout(abortTimeInMs) + const segmentTimeoutInMs = + options.segmentTimeoutInMs === undefined ? 3600000 : options.segmentTimeoutInMs + const abortSignal = AbortController.timeout(segmentTimeoutInMs) abortSignal.addEventListener('abort', () => { core.warning('Cache download aborted, segment download timed out.') }) diff --git a/src/options.ts b/src/options.ts index b556326..eefe973 100644 --- a/src/options.ts +++ b/src/options.ts @@ -48,11 +48,11 @@ export interface DownloadOptions { timeoutInMs?: number /** - * Time after which download should be aborted if stuck + * Time after which a segment download should be aborted if stuck * * @default 3600000 */ - abortTimeInMs?: number + segmentTimeoutInMs?: number } /** @@ -92,7 +92,7 @@ export function getDownloadOptions(copy?: DownloadOptions): DownloadOptions { useAzureSdk: true, downloadConcurrency: 8, timeoutInMs: 30000, - abortTimeInMs: 3600000 + segmentTimeoutInMs: 3600000 } if (copy) { @@ -108,15 +108,15 @@ export function getDownloadOptions(copy?: DownloadOptions): DownloadOptions { result.timeoutInMs = copy.timeoutInMs } - if (typeof copy.abortTimeInMs === 'number') { - result.abortTimeInMs = copy.abortTimeInMs + if (typeof copy.segmentTimeoutInMs === 'number') { + result.segmentTimeoutInMs = copy.segmentTimeoutInMs } } core.debug(`Use Azure SDK: ${result.useAzureSdk}`) core.debug(`Download concurrency: ${result.downloadConcurrency}`) core.debug(`Request timeout (ms): ${result.timeoutInMs}`) - core.debug(`Abort time (ms): ${result.abortTimeInMs}`) + core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`) return result } From 5e28be1229f2c67c327a61e739b73ff843c6e3d4 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 8 Aug 2022 04:56:02 +0000 Subject: [PATCH 12/13] Added formatting changes --- src/internal/downloadUtils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index e93a93f..d9f4bfd 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -250,7 +250,9 @@ export async function downloadCacheStorageSDK( try { downloadProgress.startDisplayTimer() const segmentTimeoutInMs = - options.segmentTimeoutInMs === undefined ? 3600000 : options.segmentTimeoutInMs + options.segmentTimeoutInMs === undefined + ? 3600000 + : options.segmentTimeoutInMs const abortSignal = AbortController.timeout(segmentTimeoutInMs) abortSignal.addEventListener('abort', () => { core.warning('Cache download aborted, segment download timed out.') From dc1b3d616b49ea52903448e1832f726fa8b8d23d Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 8 Aug 2022 13:22:11 +0000 Subject: [PATCH 13/13] Updated error message and null check --- src/internal/downloadUtils.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/internal/downloadUtils.ts b/src/internal/downloadUtils.ts index d9f4bfd..c92cc99 100644 --- a/src/internal/downloadUtils.ts +++ b/src/internal/downloadUtils.ts @@ -249,13 +249,11 @@ export async function downloadCacheStorageSDK( try { downloadProgress.startDisplayTimer() - const segmentTimeoutInMs = - options.segmentTimeoutInMs === undefined - ? 3600000 - : options.segmentTimeoutInMs - const abortSignal = AbortController.timeout(segmentTimeoutInMs) + const abortSignal = AbortController.timeout( + options.segmentTimeoutInMs || 3600000 + ) abortSignal.addEventListener('abort', () => { - core.warning('Cache download aborted, segment download timed out.') + core.warning('Aborting cache download as it exceeded the timeout.') }) while (!downloadProgress.isDone()) { const segmentStart = @@ -277,7 +275,6 @@ export async function downloadCacheStorageSDK( onProgress: downloadProgress.onProgress() } ) - fs.writeFileSync(fd, result) } } finally {