From cf4f44db70fa0ef3627a1bb7f5136becb53e2c5d Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Mon, 6 Jan 2020 13:50:39 -0500 Subject: [PATCH] Fix invalid array --- src/cacheHttpClient.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cacheHttpClient.ts b/src/cacheHttpClient.ts index 89bca63..4defdf8 100644 --- a/src/cacheHttpClient.ts +++ b/src/cacheHttpClient.ts @@ -201,11 +201,19 @@ async function uploadFile( const resourceUrl = getCacheApiUrl() + "caches/" + cacheId.toString(); const fd = fs.openSync(archivePath, "r"); - const concurrency = Number(process.env["CACHE_UPLOAD_CONCURRENCY"]) ?? 4; // # of HTTP requests in parallel - const MAX_CHUNK_SIZE = - Number(process.env["CACHE_UPLOAD_CHUNK_SIZE"]) ?? 32 * 1024 * 1024; // 32 MB Chunks - core.debug(`Concurrency: ${concurrency} and Chunk Size: ${MAX_CHUNK_SIZE}`); + let concurrency = Number(process.env["CACHE_UPLOAD_CONCURRENCY"]); // # of HTTP requests in parallel + if (Number.isNaN(concurrency) || concurrency < 0) { + concurrency = 4; + } + let MAX_CHUNK_SIZE = + Number(process.env["CACHE_UPLOAD_CHUNK_SIZE"]); + + if (Number.isNaN(MAX_CHUNK_SIZE) || MAX_CHUNK_SIZE < 0) { + concurrency = 32 * 1024 * 1024; // 32 MB Chunks + } + + core.debug(`Concurrency: ${concurrency} and Chunk Size: ${MAX_CHUNK_SIZE}`); const parallelUploads = [...new Array(concurrency).keys()]; core.debug("Awaiting all uploads"); let offset = 0;