From 8f6c91c2de31f6dc68c9f2474c38349a7e540a93 Mon Sep 17 00:00:00 2001 From: Denys Zhdanov Date: Thu, 13 Jun 2024 10:31:20 +0200 Subject: [PATCH] Making flc thread safe with mutex --- carbonserver/flc.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/carbonserver/flc.go b/carbonserver/flc.go index 2941115c6..ce97671d2 100644 --- a/carbonserver/flc.go +++ b/carbonserver/flc.go @@ -10,6 +10,7 @@ import ( "io" "os" "strings" + "sync" ) // file list cache @@ -82,6 +83,7 @@ type fileListCacheCommon struct { path string mode byte file *os.File + mutex sync.Mutex reader *gzip.Reader writer *gzip.Writer } @@ -237,6 +239,8 @@ func newFileListCacheV1ReadOnly(flcc *fileListCacheCommon) *fileListCacheV1 { } func (flc *fileListCacheV1) Write(entry *FLCEntry) error { + flc.mutex.Lock() + defer flc.mutex.Unlock() _, err := flc.writer.Write([]byte(entry.Path + "\n")) return err } @@ -299,7 +303,9 @@ func (flc *fileListCacheV2) Write(entry *FLCEntry) error { offset += flcv2StatFieldSize buf[offset] = '\n' - + + flc.mutex.Lock() + defer flc.mutex.Unlock() _, err := flc.writer.Write(buf) return err