mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2025-08-22 00:29:09 +08:00
Added abort controller for timer
This commit is contained in:
parent
e5e69a3171
commit
970264135a
7
packages/cache/src/internal/downloadUtils.ts
vendored
7
packages/cache/src/internal/downloadUtils.ts
vendored
@ -251,6 +251,7 @@ export async function downloadCacheStorageSDK(
|
|||||||
try {
|
try {
|
||||||
downloadProgress.startDisplayTimer()
|
downloadProgress.startDisplayTimer()
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
|
const timerController = new AbortController();
|
||||||
const abortSignal = controller.signal;
|
const abortSignal = controller.signal;
|
||||||
while (!downloadProgress.isDone()) {
|
while (!downloadProgress.isDone()) {
|
||||||
const segmentStart =
|
const segmentStart =
|
||||||
@ -262,7 +263,6 @@ export async function downloadCacheStorageSDK(
|
|||||||
)
|
)
|
||||||
|
|
||||||
downloadProgress.nextSegment(segmentSize)
|
downloadProgress.nextSegment(segmentSize)
|
||||||
|
|
||||||
const result = await Promise.race([client.downloadToBuffer(
|
const result = await Promise.race([client.downloadToBuffer(
|
||||||
segmentStart,
|
segmentStart,
|
||||||
segmentSize,
|
segmentSize,
|
||||||
@ -272,11 +272,14 @@ export async function downloadCacheStorageSDK(
|
|||||||
onProgress: downloadProgress.onProgress()
|
onProgress: downloadProgress.onProgress()
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
timer.setTimeout(options.abortTimeInMs, 'timeout')]);
|
timer.setTimeout(options.abortTimeInMs, 'timeout',{ signal: timerController.signal })]);
|
||||||
|
|
||||||
if(result === 'timeout') {
|
if(result === 'timeout') {
|
||||||
controller.abort();
|
controller.abort();
|
||||||
throw new Error("Download aborted, segment download timed out.");
|
throw new Error("Download aborted, segment download timed out.");
|
||||||
|
} else {
|
||||||
|
timerController.abort();
|
||||||
|
core.debug("Download completely successfully, cancelling timer.")
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(fd, result)
|
fs.writeFileSync(fd, result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user