From 3a3d576d9b707c78836b52d210ab15a1efa75911 Mon Sep 17 00:00:00 2001 From: Maximillian von Briesen Date: Tue, 8 Oct 2019 17:01:32 -0400 Subject: [PATCH] satellite/audit: add mutex to pieceHashesVerified map (#3214) * add mutex * remove double send to ch * lock mutex inside defer * import sync --- satellite/audit/verifier.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/satellite/audit/verifier.go b/satellite/audit/verifier.go index e75f49653..1554db8ee 100644 --- a/satellite/audit/verifier.go +++ b/satellite/audit/verifier.go @@ -8,6 +8,7 @@ import ( "context" "io" "math/rand" + "sync" "time" "github.com/vivint/infectious" @@ -359,7 +360,10 @@ func (verifier *Verifier) Reverify(ctx context.Context, path storj.Path) (report } pieceHashesVerified := make(map[storj.NodeID]bool) + pieceHashesVerifiedMutex := &sync.Mutex{} defer func() { + pieceHashesVerifiedMutex.Lock() + // for each node in Fails and PendingAudits, remove if piece hashes not verified for that segment newFails := storj.NodeIDList{} newPendingAudits := []*PendingAudit{} @@ -377,6 +381,8 @@ func (verifier *Verifier) Reverify(ctx context.Context, path storj.Path) (report report.Fails = newFails report.PendingAudits = newPendingAudits + + pieceHashesVerifiedMutex.Unlock() }() pieces := pointer.GetRemote().GetRemotePieces() @@ -415,7 +421,9 @@ func (verifier *Verifier) Reverify(ctx context.Context, path storj.Path) (report } // set whether piece hashes have been verified for this segment so we know whether to report a failed or pending audit for this node + pieceHashesVerifiedMutex.Lock() pieceHashesVerified[pending.NodeID] = pendingPointer.PieceHashesVerified + pieceHashesVerifiedMutex.Unlock() if pendingPointer.GetRemote().RootPieceId != pending.PieceID { // segment has changed since initial containment @@ -436,7 +444,6 @@ func (verifier *Verifier) Reverify(ctx context.Context, path storj.Path) (report } if !found { // node is no longer in pointer, so remove from containment - ch <- result{nodeID: pending.NodeID, status: erred, err: err} _, errDelete := verifier.containment.Delete(ctx, pending.NodeID) if errDelete != nil { verifier.log.Debug("Error deleting node from containment db", zap.String("Segment Path", pending.Path), zap.Stringer("Node ID", pending.NodeID), zap.Error(errDelete))