1
0
Fork 0

wrapping timeout in try catch

pull/1712/head
Vallie Joseph 2024-04-09 21:18:30 +00:00
parent 18a8a22c65
commit fa9db3c8fa
1 changed files with 8 additions and 4 deletions

View File

@ -25,6 +25,8 @@ export async function uploadZipToBlobStorage(
): Promise<BlobUploadResponse> { ): Promise<BlobUploadResponse> {
let uploadByteCount = 0 let uploadByteCount = 0
let lastProgressTime = Date.now() let lastProgressTime = Date.now()
let timeoutId: NodeJS.Timeout | undefined
const chunkTimer = (timeout: number): NodeJS.Timeout => const chunkTimer = (timeout: number): NodeJS.Timeout =>
setTimeout(() => { setTimeout(() => {
const now = Date.now() const now = Date.now()
@ -34,7 +36,6 @@ export async function uploadZipToBlobStorage(
throw new Error('Upload progress stalled.') throw new Error('Upload progress stalled.')
} }
}, timeout) }, timeout)
const maxConcurrency = getConcurrency() const maxConcurrency = getConcurrency()
const bufferSize = getUploadChunkSize() const bufferSize = getUploadChunkSize()
const blobClient = new BlobClient(authenticatedUploadURL) const blobClient = new BlobClient(authenticatedUploadURL)
@ -69,6 +70,8 @@ export async function uploadZipToBlobStorage(
core.info('Beginning upload of artifact content to blob storage') core.info('Beginning upload of artifact content to blob storage')
try { try {
// Start the chunk timer
timeoutId = chunkTimer(timeoutDuration)
await blockBlobClient.uploadStream( await blockBlobClient.uploadStream(
uploadStream, uploadStream,
bufferSize, bufferSize,
@ -79,11 +82,12 @@ export async function uploadZipToBlobStorage(
if (NetworkError.isNetworkErrorCode(error?.code)) { if (NetworkError.isNetworkErrorCode(error?.code)) {
throw new NetworkError(error?.code) throw new NetworkError(error?.code)
} }
throw error throw error
} finally { } finally {
// clear the progress timeout when upload completes // clear the timeout whether or not the upload completes
clearTimeout(chunkTimer(timeoutDuration)) if (timeoutId) {
clearTimeout(timeoutId)
}
} }
core.info('Finished uploading artifact content to blob storage!') core.info('Finished uploading artifact content to blob storage!')