From c202c38407d5fe9fce9e010fa5547f2ffecb53b4 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 16 Aug 2022 04:14:27 +0000 Subject: [PATCH] Added custom user inputted timeout --- packages/cache/RELEASES.md | 5 ++++- packages/cache/__tests__/options.test.ts | 18 ++++++++++++++++++ packages/cache/package-lock.json | 4 ++-- packages/cache/package.json | 2 +- packages/cache/src/options.ts | 11 +++++++++++ 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/packages/cache/RELEASES.md b/packages/cache/RELEASES.md index 8fc7ba29..8ffe364c 100644 --- a/packages/cache/RELEASES.md +++ b/packages/cache/RELEASES.md @@ -80,4 +80,7 @@ - Added 1 hour timeout for the download stuck issue [#810](https://github.com/actions/cache/issues/810). ### 3.0.3 -- Bug fixes for download stuck issue [#810](https://github.com/actions/cache/issues/810). \ No newline at end of file +- Bug fixes for download stuck issue [#810](https://github.com/actions/cache/issues/810). + +### 3.0.4 +- Allowing users to provide a custom timeout as input for aborting cache download using an environment variable `CACHE_DOWNLOAD_TIMEOUT_MINS`. Default is 1 hour. \ No newline at end of file diff --git a/packages/cache/__tests__/options.test.ts b/packages/cache/__tests__/options.test.ts index 5ec7b146..e2cdf468 100644 --- a/packages/cache/__tests__/options.test.ts +++ b/packages/cache/__tests__/options.test.ts @@ -55,3 +55,21 @@ test('getUploadOptions overrides all settings', async () => { expect(actualOptions).toEqual(expectedOptions) }) + +test('getDownloadOptions overrides download timeout minutes', async () => { + const expectedOptions: DownloadOptions = { + useAzureSdk: false, + downloadConcurrency: 14, + timeoutInMs: 20000, + segmentTimeoutInMs: 3600000 + } + process.env.CACHE_DOWNLOAD_TIMEOUT_MINS = '10' + const actualOptions = getDownloadOptions(expectedOptions) + + expect(actualOptions.useAzureSdk).toEqual(expectedOptions.useAzureSdk) + expect(actualOptions.downloadConcurrency).toEqual( + expectedOptions.downloadConcurrency + ) + expect(actualOptions.timeoutInMs).toEqual(expectedOptions.timeoutInMs) + expect(actualOptions.segmentTimeoutInMs).toEqual(600000) +}) diff --git a/packages/cache/package-lock.json b/packages/cache/package-lock.json index 87d24d4d..0ea84f44 100644 --- a/packages/cache/package-lock.json +++ b/packages/cache/package-lock.json @@ -1,12 +1,12 @@ { "name": "@actions/cache", - "version": "3.0.3", + "version": "3.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@actions/cache", - "version": "3.0.3", + "version": "3.0.4", "license": "MIT", "dependencies": { "@actions/core": "^1.2.6", diff --git a/packages/cache/package.json b/packages/cache/package.json index 476e8562..6a3d476f 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -1,6 +1,6 @@ { "name": "@actions/cache", - "version": "3.0.3", + "version": "3.0.4", "preview": true, "description": "Actions cache lib", "keywords": [ diff --git a/packages/cache/src/options.ts b/packages/cache/src/options.ts index eefe9731..d3f716b8 100644 --- a/packages/cache/src/options.ts +++ b/packages/cache/src/options.ts @@ -112,10 +112,21 @@ export function getDownloadOptions(copy?: DownloadOptions): DownloadOptions { result.segmentTimeoutInMs = copy.segmentTimeoutInMs } } + const customDownloadTimeoutMins = process.env['CACHE_DOWNLOAD_TIMEOUT_MINS'] + if ( + customDownloadTimeoutMins && + !isNaN(Number(customDownloadTimeoutMins)) && + isFinite(Number(customDownloadTimeoutMins)) + ) { + result.segmentTimeoutInMs = Number(customDownloadTimeoutMins) * 60 * 1000 + } core.debug(`Use Azure SDK: ${result.useAzureSdk}`) core.debug(`Download concurrency: ${result.downloadConcurrency}`) core.debug(`Request timeout (ms): ${result.timeoutInMs}`) + core.debug( + `Cache download timeout mins env var: ${process.env['CACHE_DOWNLOAD_TIMEOUT_MINS']}` + ) core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`) return result