From 1e1aa94ffbc95f5fd2056037d7de6d3d74f8fce6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 29 Aug 2023 11:04:11 +0200 Subject: [PATCH] lib/logstorage: eliminate data race when clearing s.ptwHot after deleting the corresponding partition The previous code could result in the following data race: 1. The s.ptwHot partition is marked to be deleted 2. ptw.decRef() is called on it 3. ptw.pt is set to nil 4. s.ptwHot.pt is accessed from concurrent goroutine, which leads to panic. The change clears s.ptwHot under s.partitionsLock in order to prevent from the data race. This is a follow-up for 8d50032dd6a18b598c18da15d8d2e53a704ef8e9 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4895 --- lib/logstorage/storage.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/logstorage/storage.go b/lib/logstorage/storage.go index 0216be2821..a15fd76e76 100644 --- a/lib/logstorage/storage.go +++ b/lib/logstorage/storage.go @@ -317,6 +317,9 @@ func (s *Storage) watchRetention() { break } ptwsToDelete = append(ptwsToDelete, ptw) + if ptw == s.ptwHot { + s.ptwHot = nil + } } for i := range ptwsToDelete { s.partitions[i] = nil