Skip to content

Commit 40eb32f

Browse files
rprovodenkodelvedor
authored andcommitted
Fix onFlushTimeout timer not being cleared when upstream errors (#1616)
1 parent b648f7c commit 40eb32f

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/helpers.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,21 +356,24 @@ export default class Helpers {
356356
let loadedOperations = 0
357357
timeoutRef = setTimeout(onFlushTimeout, flushInterval) // eslint-disable-line
358358

359-
for await (const operation of operationsStream) {
360-
timeoutRef.refresh()
361-
loadedOperations += 1
362-
msearchBody.push(operation[0], operation[1])
363-
callbacks.push(operation[2])
364-
if (loadedOperations >= operations) {
365-
const send = await semaphore()
366-
send(msearchBody.slice(), callbacks.slice())
367-
msearchBody.length = 0
368-
callbacks.length = 0
369-
loadedOperations = 0
359+
try {
360+
for await (const operation of operationsStream) {
361+
timeoutRef.refresh()
362+
loadedOperations += 1
363+
msearchBody.push(operation[0], operation[1])
364+
callbacks.push(operation[2])
365+
if (loadedOperations >= operations) {
366+
const send = await semaphore()
367+
send(msearchBody.slice(), callbacks.slice())
368+
msearchBody.length = 0
369+
callbacks.length = 0
370+
loadedOperations = 0
371+
}
370372
}
373+
} finally {
374+
clearTimeout(timeoutRef)
371375
}
372376

373-
clearTimeout(timeoutRef)
374377
// In some cases the previos http call does not have finished,
375378
// or we didn't reach the flush bytes threshold, so we force one last operation.
376379
if (loadedOperations > 0) {

0 commit comments

Comments
 (0)