From abf01a0eb724aa82a5b2465c1dbde67bcc795727 Mon Sep 17 00:00:00 2001 From: "M@" Date: Thu, 25 Apr 2024 18:46:12 -0400 Subject: [PATCH] Fixes unlocked read from logBuffer.LastTsNs that is racey. (#5536) --- weed/util/log_buffer/log_read.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/weed/util/log_buffer/log_read.go b/weed/util/log_buffer/log_read.go index c3dd0f288..0d044fc14 100644 --- a/weed/util/log_buffer/log_read.go +++ b/weed/util/log_buffer/log_read.go @@ -66,9 +66,17 @@ func (logBuffer *LogBuffer) LoopProcessLogData(readerName string, startPosition isDone = true return } + logBuffer.RLock() lastTsNs := logBuffer.LastTsNs - for lastTsNs == logBuffer.LastTsNs { + logBuffer.RUnlock() + loopTsNs := lastTsNs // make a copy + + for lastTsNs == loopTsNs { if waitForDataFn() { + // Update loopTsNs and loop again + logBuffer.RLock() + loopTsNs = logBuffer.LastTsNs + logBuffer.RUnlock() continue } else { isDone = true