mirror of https://github.com/actions/toolkit
Removed custom promise and used abort timeout
parent
ef888588c1
commit
83becb7900
|
@ -249,7 +249,12 @@ export async function downloadCacheStorageSDK(
|
||||||
|
|
||||||
try {
|
try {
|
||||||
downloadProgress.startDisplayTimer()
|
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()) {
|
while (!downloadProgress.isDone()) {
|
||||||
const segmentStart =
|
const segmentStart =
|
||||||
downloadProgress.segmentOffset + downloadProgress.segmentSize
|
downloadProgress.segmentOffset + downloadProgress.segmentSize
|
||||||
|
@ -260,22 +265,18 @@ export async function downloadCacheStorageSDK(
|
||||||
)
|
)
|
||||||
|
|
||||||
downloadProgress.nextSegment(segmentSize)
|
downloadProgress.nextSegment(segmentSize)
|
||||||
const abortTimeInMs =
|
|
||||||
options.abortTimeInMs === undefined ? 3600000 : options.abortTimeInMs
|
const result = await client.downloadToBuffer(
|
||||||
const result = await promiseWithTimeout(
|
segmentStart,
|
||||||
abortTimeInMs,
|
segmentSize,
|
||||||
client.downloadToBuffer(segmentStart, segmentSize, {
|
{
|
||||||
abortSignal: controller.signal,
|
abortSignal: abortSignal,
|
||||||
concurrency: options.downloadConcurrency,
|
concurrency: options.downloadConcurrency,
|
||||||
onProgress: downloadProgress.onProgress()
|
onProgress: downloadProgress.onProgress()
|
||||||
})
|
}
|
||||||
)
|
)
|
||||||
if (result === 'timeout') {
|
|
||||||
controller.abort()
|
fs.writeFileSync(fd, result)
|
||||||
throw new Error('Download aborted, segment download timed out.')
|
|
||||||
} else if (Buffer.isBuffer(result)) {
|
|
||||||
fs.writeFileSync(fd, result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
downloadProgress.stopDisplayTimer()
|
downloadProgress.stopDisplayTimer()
|
||||||
|
@ -283,18 +284,3 @@ export async function downloadCacheStorageSDK(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const promiseWithTimeout = async (
|
|
||||||
timeoutMs: number,
|
|
||||||
promise: Promise<Buffer>
|
|
||||||
): Promise<unknown> => {
|
|
||||||
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue