1
0
Fork 0

add timeout in between data chunks

vmjoseph/download-v4-client-blob
Rob Herley 2023-12-20 13:59:31 -05:00
parent 2d6ba67518
commit 34a411f3c0
No known key found for this signature in database
GPG Key ID: D1602042C3543B06
1 changed files with 20 additions and 1 deletions

View File

@ -67,11 +67,30 @@ async function streamExtractInternal(
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const zipStream = unzip.Extract({path: directory}) const zipStream = unzip.Extract({path: directory})
const timeout = 30 * 1000
const timerFn = (): void => {
throw new Error(`Blob storage chunk did not respond in ${timeout}ms `)
}
let timer = setTimeout(timerFn, timeout)
try { try {
response.message.pipe(zipStream).on('close', resolve).on('error', reject) response.message
.on('data', () => {
clearTimeout(timer)
timer = setTimeout(timerFn, timeout)
})
.pipe(zipStream)
.on('close', () => {
clearTimeout(timer)
resolve()
})
.on('error', reject)
} catch (error) { } catch (error) {
zipStream.end() zipStream.end()
reject(error) reject(error)
} finally {
clearTimeout(timer)
} }
}) })
} }