mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2025-08-16 19:05:54 +08:00
Added abortController to stop download
This commit is contained in:
parent
d8b119ca22
commit
e5e69a3171
11
packages/cache/src/internal/downloadUtils.ts
vendored
11
packages/cache/src/internal/downloadUtils.ts
vendored
@ -13,6 +13,8 @@ import {SocketTimeout} from './constants'
|
|||||||
import {DownloadOptions} from '../options'
|
import {DownloadOptions} from '../options'
|
||||||
import {retryHttpClientResponse} from './requestUtils'
|
import {retryHttpClientResponse} from './requestUtils'
|
||||||
|
|
||||||
|
import { AbortController } from "@azure/abort-controller";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pipes the body of a HTTP response to a stream
|
* Pipes the body of a HTTP response to a stream
|
||||||
*
|
*
|
||||||
@ -248,7 +250,8 @@ export async function downloadCacheStorageSDK(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
downloadProgress.startDisplayTimer()
|
downloadProgress.startDisplayTimer()
|
||||||
|
const controller = new AbortController();
|
||||||
|
const abortSignal = controller.signal;
|
||||||
while (!downloadProgress.isDone()) {
|
while (!downloadProgress.isDone()) {
|
||||||
const segmentStart =
|
const segmentStart =
|
||||||
downloadProgress.segmentOffset + downloadProgress.segmentSize
|
downloadProgress.segmentOffset + downloadProgress.segmentSize
|
||||||
@ -264,14 +267,16 @@ export async function downloadCacheStorageSDK(
|
|||||||
segmentStart,
|
segmentStart,
|
||||||
segmentSize,
|
segmentSize,
|
||||||
{
|
{
|
||||||
|
abortSignal: abortSignal,
|
||||||
concurrency: options.downloadConcurrency,
|
concurrency: options.downloadConcurrency,
|
||||||
onProgress: downloadProgress.onProgress()
|
onProgress: downloadProgress.onProgress()
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
timer.setTimeout(60 * 60 * 1000, 'timeout')]);
|
timer.setTimeout(options.abortTimeInMs, 'timeout')]);
|
||||||
|
|
||||||
if(result === '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)
|
fs.writeFileSync(fd, result)
|
||||||
|
17
packages/cache/src/options.ts
vendored
17
packages/cache/src/options.ts
vendored
@ -46,6 +46,15 @@ export interface DownloadOptions {
|
|||||||
* @default 30000
|
* @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 = {
|
const result: DownloadOptions = {
|
||||||
useAzureSdk: true,
|
useAzureSdk: true,
|
||||||
downloadConcurrency: 8,
|
downloadConcurrency: 8,
|
||||||
timeoutInMs: 30000
|
timeoutInMs: 30000,
|
||||||
|
abortTimeInMs: 2700000
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy) {
|
if (copy) {
|
||||||
@ -99,11 +109,16 @@ export function getDownloadOptions(copy?: DownloadOptions): DownloadOptions {
|
|||||||
if (typeof copy.timeoutInMs === 'number') {
|
if (typeof copy.timeoutInMs === 'number') {
|
||||||
result.timeoutInMs = copy.timeoutInMs
|
result.timeoutInMs = copy.timeoutInMs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof copy.abortTimeInMs === 'number') {
|
||||||
|
result.abortTimeInMs = copy.abortTimeInMs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(`Use Azure SDK: ${result.useAzureSdk}`)
|
core.debug(`Use Azure SDK: ${result.useAzureSdk}`)
|
||||||
core.debug(`Download concurrency: ${result.downloadConcurrency}`)
|
core.debug(`Download concurrency: ${result.downloadConcurrency}`)
|
||||||
core.debug(`Request timeout (ms): ${result.timeoutInMs}`)
|
core.debug(`Request timeout (ms): ${result.timeoutInMs}`)
|
||||||
|
core.debug(`Abort time (ms): ${result.abortTimeInMs}`)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user