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

Commit

Permalink
Merge pull request #154 from jsign/jsign/fixraces
Browse files Browse the repository at this point in the history
addrbook: fix races
  • Loading branch information
vyzo authored Jun 5, 2020
2 parents ce24bfc + 1542834 commit 9827ee0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pstoreds/addr_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand Down Expand Up @@ -316,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,
Expand All @@ -334,6 +337,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
}
Expand Down

0 comments on commit 9827ee0

Please sign in to comment.