lib/storage: prevent possible race condition when all the goroutines exit Storage.AddRows, before goroutines other goroutines are blocked on searchTSIDsCond inside Storage.searchTSIDs

This condition may occur after the following sequence of events:

1) A goroutine enters the loop body when len(addRowsConcurrencyCh) == cap(addRowsConcurrencyCh) inside Storage.searchTSIDs.
2) All the goroutines return from Storage.AddRows.
3) The goroutine from step 1 blocks on searchTSIDsCond.Wait() inside the loop body.

The goroutine remains blocked until the next call to Storage.AddRows, which calls searchTSIDsCond.Signal().
This may take indefinite time.
This commit is contained in:
Aliaksandr Valialkin 2020-07-22 21:46:38 +03:00
parent 71c3266fca
commit 754eac676d

View file

@ -1112,8 +1112,10 @@ func (s *Storage) AddRows(mrs []MetricRow, precisionBits uint8) error {
putRawRows(rr) putRawRows(rr)
// Notify blocked goroutines at Storage.searchTSIDs that they may proceed with their work. // Notify blocked goroutines at Storage.searchTSIDs that they may proceed with their work.
searchTSIDsCondLock.Lock()
<-addRowsConcurrencyCh <-addRowsConcurrencyCh
searchTSIDsCond.Signal() searchTSIDsCond.Signal()
searchTSIDsCondLock.Unlock()
return err return err
} }