From 916a3e196ea0013553ac47acc86f5eae95c99737 Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 12 Oct 2018 13:55:47 +0200 Subject: [PATCH] swarm/storage: Eliminate potential duplicate gc under lock --- swarm/storage/ldbstore.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/swarm/storage/ldbstore.go b/swarm/storage/ldbstore.go index e6f277110d..49508911f9 100644 --- a/swarm/storage/ldbstore.go +++ b/swarm/storage/ldbstore.go @@ -314,10 +314,12 @@ func decodeData(addr Address, data []byte) (*chunk, error) { func (s *LDBStore) collectGarbage() error { // prevent duplicate gc from starting when one is already running - if len(s.gc.runC) == 0 { + select { + case <-s.gc.runC: + default: return nil } - <-s.gc.runC + s.lock.Lock() entryCnt := s.entryCnt s.lock.Unlock()