Skip to content

Commit d015828

Browse files
authored
Fix onFlushTimeout timer not being cleared when upstream errors (#1616)
1 parent e7c5b3d commit d015828

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
@@ -355,21 +355,24 @@ export default class Helpers {
355355
let loadedOperations = 0
356356
timeoutRef = setTimeout(onFlushTimeout, flushInterval) // eslint-disable-line
357357

358-
for await (const operation of operationsStream) {
359-
timeoutRef.refresh()
360-
loadedOperations += 1
361-
msearchBody.push(operation[0], operation[1])
362-
callbacks.push(operation[2])
363-
if (loadedOperations >= operations) {
364-
const send = await semaphore()
365-
send(msearchBody.slice(), callbacks.slice())
366-
msearchBody.length = 0
367-
callbacks.length = 0
368-
loadedOperations = 0
358+
try {
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
370+
}
369371
}
372+
} finally {
373+
clearTimeout(timeoutRef)
370374
}
371375

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

0 commit comments

Comments
 (0)