Prechádzať zdrojové kódy

bitseq: fix races

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
Alexander Morozov 9 rokov pred
rodič
commit
a9c3a9821b

+ 2 - 0
libnetwork/bitseq/sequence.go

@@ -370,6 +370,8 @@ func (h *Handle) set(ordinal, start, end uint64, any bool, release bool) (uint64
 
 // checks is needed because to cover the case where the number of bits is not a multiple of blockLen
 func (h *Handle) validateOrdinal(ordinal uint64) error {
+	h.Lock()
+	defer h.Unlock()
 	if ordinal >= h.bits {
 		return fmt.Errorf("bit does not belong to the sequence")
 	}

+ 5 - 0
libnetwork/bitseq/store.go

@@ -75,6 +75,10 @@ func (h *Handle) CopyTo(o datastore.KVObject) error {
 	defer h.Unlock()
 
 	dstH := o.(*Handle)
+	if h == dstH {
+		return nil
+	}
+	dstH.Lock()
 	dstH.bits = h.bits
 	dstH.unselected = h.unselected
 	dstH.head = h.head.getCopy()
@@ -83,6 +87,7 @@ func (h *Handle) CopyTo(o datastore.KVObject) error {
 	dstH.dbIndex = h.dbIndex
 	dstH.dbExists = h.dbExists
 	dstH.store = h.store
+	dstH.Unlock()
 
 	return nil
 }