Skip to content

Commit

Permalink
Fix race condition for logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslabari committed Mar 13, 2024
1 parent 2f6c705 commit 4da6077
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 4da6077

Please sign in to comment.