Skip to content

Commit

Permalink
Merge pull request #559 from embrace-io/lucas/fix_race_condition_on_logs
Browse files Browse the repository at this point in the history
Fix race condition for logs.
  • Loading branch information
lucaslabari committed Mar 13, 2024
2 parents 34af6df + 4da6077 commit 7883bac
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ internal class LogSinkImpl : LogSink {

override fun flushLogs(max: Int?): List<EmbraceLogRecordData> {
synchronized(flushLock) {
val currentSize = storedLogs.size
val maxIndex = max?.let {
minOf(storedLogs.size, it)
} ?: storedLogs.size
minOf(currentSize, it)
} ?: currentSize
val flushedLogs = storedLogs.take(maxIndex)
storedLogs.removeAll(flushedLogs.toSet())
return flushedLogs
Expand Down

0 comments on commit 7883bac

Please sign in to comment.