1
0
Fork 0

Removed abortcontroller

kotewar/remove-timeout
Sankalp Kotewar 2023-03-24 10:29:06 +00:00 committed by GitHub
parent 457303960f
commit 0f583c7958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 38 deletions

12
packages/cache/package-lock.json generated vendored
View File

@ -69,9 +69,9 @@
} }
}, },
"node_modules/@actions/io": { "node_modules/@actions/io": {
"version": "1.1.2", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.2.tgz", "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz",
"integrity": "sha512-d+RwPlMp+2qmBfeLYPLXuSRykDIFEwdTA0MMxzS9kh4kvP1ftrc/9fzy6pX6qAjthdXruHQ6/6kjT/DNo5ALuw==" "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="
}, },
"node_modules/@azure/abort-controller": { "node_modules/@azure/abort-controller": {
"version": "1.1.0", "version": "1.1.0",
@ -654,9 +654,9 @@
} }
}, },
"@actions/io": { "@actions/io": {
"version": "1.1.2", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.2.tgz", "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz",
"integrity": "sha512-d+RwPlMp+2qmBfeLYPLXuSRykDIFEwdTA0MMxzS9kh4kvP1ftrc/9fzy6pX6qAjthdXruHQ6/6kjT/DNo5ALuw==" "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="
}, },
"@azure/abort-controller": { "@azure/abort-controller": {
"version": "1.1.0", "version": "1.1.0",

View File

@ -12,8 +12,6 @@ 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
* *
@ -251,8 +249,8 @@ export async function downloadCacheStorageSDK(
try { try {
downloadProgress.startDisplayTimer() downloadProgress.startDisplayTimer()
const controller = new AbortController() // const controller = new AbortController()
const abortSignal = controller.signal // const abortSignal = controller.signal
while (!downloadProgress.isDone()) { while (!downloadProgress.isDone()) {
const segmentStart = const segmentStart =
downloadProgress.segmentOffset + downloadProgress.segmentSize downloadProgress.segmentOffset + downloadProgress.segmentSize
@ -263,22 +261,15 @@ export async function downloadCacheStorageSDK(
) )
downloadProgress.nextSegment(segmentSize) downloadProgress.nextSegment(segmentSize)
const result = await promiseWithTimeout( const result = await client.downloadToBuffer(
options.segmentTimeoutInMs || 3600000, segmentStart,
client.downloadToBuffer(segmentStart, segmentSize, { segmentSize,
abortSignal, {
concurrency: options.downloadConcurrency, concurrency: options.downloadConcurrency,
onProgress: downloadProgress.onProgress() onProgress: downloadProgress.onProgress()
}) }
) )
if (result === 'timeout') { fs.writeFileSync(fd, result)
controller.abort()
throw new Error(
'Aborting cache download as the download time exceeded the timeout.'
)
} else if (Buffer.isBuffer(result)) {
fs.writeFileSync(fd, result)
}
} }
} finally { } finally {
downloadProgress.stopDisplayTimer() downloadProgress.stopDisplayTimer()
@ -286,18 +277,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
})
}