From fd7abf186da1895e20dd2fdb2e8a1406e60081d7 Mon Sep 17 00:00:00 2001 From: Jeroen Wijenbergh Date: Thu, 12 Feb 2026 11:45:13 +0100 Subject: Log Rotater: Fix data race We were accessing the file using stat and trimming + replacing the file handler possibly at the same time. Just put a mutex over everything to protect it better. This was caught using Go's race detector --- internal/log/rotate.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/log/rotate.go b/internal/log/rotate.go index 27907ce..2971f70 100644 --- a/internal/log/rotate.go +++ b/internal/log/rotate.go @@ -50,8 +50,6 @@ func (fr *FileRotater) open() error { } func (fr *FileRotater) trim() error { - fr.mu.Lock() - defer fr.mu.Unlock() // We need to seek to the trim size to skip over that part as we discard it _, err := fr.file.Seek(TrimSize, io.SeekStart) if err != nil { @@ -85,6 +83,8 @@ func (fr *FileRotater) trim() error { // Write implements io.Writer for the log rotater func (fr *FileRotater) Write(p []byte) (n int, err error) { + fr.mu.Lock() + defer fr.mu.Unlock() fi, err := fr.file.Stat() if err != nil { return 0, err -- cgit v1.2.3