From 33ea6928174269772128a1d36e0b3c31e6e0054b Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Fri, 5 Jun 2020 15:02:43 -0300 Subject: [PATCH 1/2] fix race Signed-off-by: Ignacio Hagopian --- pstoreds/addr_book.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pstoreds/addr_book.go b/pstoreds/addr_book.go index 8808210..36e1db2 100644 --- a/pstoreds/addr_book.go +++ b/pstoreds/addr_book.go @@ -3,11 +3,12 @@ package pstoreds import ( "context" "fmt" - "github.com/libp2p/go-libp2p-core/record" "sort" "sync" "time" + "github.com/libp2p/go-libp2p-core/record" + ds "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/query" logging "github.com/ipfs/go-log" @@ -17,7 +18,7 @@ import ( pb "github.com/libp2p/go-libp2p-peerstore/pb" "github.com/libp2p/go-libp2p-peerstore/pstoremem" - "github.com/hashicorp/golang-lru" + lru "github.com/hashicorp/golang-lru" b32 "github.com/multiformats/go-base32" ma "github.com/multiformats/go-multiaddr" ) @@ -334,6 +335,8 @@ func (ab *dsAddrBook) GetPeerRecord(p peer.ID) *record.Envelope { log.Errorf("unable to load record for peer %s: %v", p.Pretty(), err) return nil } + pr.RLock() + defer pr.RUnlock() if pr.CertifiedRecord == nil || len(pr.CertifiedRecord.Raw) == 0 || len(pr.Addrs) == 0 { return nil } From 15428348788a3c50b7b147eb3cd0ba96677aa7be Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Fri, 5 Jun 2020 15:17:36 -0300 Subject: [PATCH 2/2] fix other race Signed-off-by: Ignacio Hagopian --- pstoreds/addr_book.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pstoreds/addr_book.go b/pstoreds/addr_book.go index 36e1db2..7368718 100644 --- a/pstoreds/addr_book.go +++ b/pstoreds/addr_book.go @@ -317,6 +317,8 @@ func (ab *dsAddrBook) storeSignedPeerRecord(p peer.ID, envelope *record.Envelope if err != nil { return err } + pr.Lock() + defer pr.Unlock() pr.CertifiedRecord = &pb.AddrBookRecord_CertifiedRecord{ Seq: rec.Seq, Raw: envelopeBytes,