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

addrbook: fix races #154

Merged
merged 2 commits into from
Jun 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 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 @@ -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()
vyzo marked this conversation as resolved.
Show resolved Hide resolved
if pr.CertifiedRecord == nil || len(pr.CertifiedRecord.Raw) == 0 || len(pr.Addrs) == 0 {
return nil
}
Expand Down