Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
swarm/storage: prevent data race on LDBStore.batchesC
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Feb 8, 2019
1 parent d233560 commit edfee9c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion swarm/storage/ldbstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,12 @@ func (s *LDBStore) Put(ctx context.Context, chunk Chunk) error {
gcIdxKey := getGCIdxKey(&index)
gcIdxData := getGCIdxValue(&index, po, chunk.Address())
s.batch.Put(gcIdxKey, gcIdxData)
s.lock.Unlock()

select {
case s.batchesC <- struct{}{}:
default:
}
s.lock.Unlock()

select {
case <-batch.c:
Expand Down Expand Up @@ -1049,7 +1049,9 @@ func (s *LDBStore) Close() {
s.lock.Unlock()
// force writing out current batch
s.writeCurrentBatch()
s.lock.Lock()
close(s.batchesC)
s.lock.Unlock()
s.db.Close()
}

Expand Down

0 comments on commit edfee9c

Please sign in to comment.