Skip to content

Commit

Permalink
Fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
guifel authored Nov 19, 2024
1 parent 57b594d commit 34aac39
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/batcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,21 @@ class Batcher {
}
}

const savedBatchStreams = this.batch.streams

// No need to clear the batch if batching is disabled
logEntry === undefined && this.clearBatch()

// Send the data to Grafana Loki
req.post(this.url, this.contentType, this.options.headers, reqBody, this.options.timeout, this.options.httpAgent, this.options.httpsAgent)
.then(() => {
// No need to clear the batch if batching is disabled
logEntry === undefined && this.clearBatch()
this.batchSent()
resolve()
})
.catch(err => {
// Revert batch for the logs to be sent on the next iteration
this.batch.streams = savedBatchStreams

// Clear the batch on error if enabled
this.options.clearOnError && this.clearBatch()

Expand Down

0 comments on commit 34aac39

Please sign in to comment.