summaryrefslogtreecommitdiff
path: root/internal/log
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroen.wijenbergh@geant.org>2026-02-12 11:45:13 +0100
committerJeroen Wijenbergh <jeroen.wijenbergh@geant.org>2026-02-12 11:45:13 +0100
commitfd7abf186da1895e20dd2fdb2e8a1406e60081d7 (patch)
treeca546d0f4e3e8db88fac7315c980ad8920b13cbe /internal/log
parent4fb31e8448c41c2199d3469913ae4c2a9b3db9fb (diff)
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
Diffstat (limited to 'internal/log')
-rw-r--r--internal/log/rotate.go4
1 files 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