Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identify: fix faulty handling of conn entries in IdentifyWait #2982

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
15 changes: 8 additions & 7 deletions p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ type idService struct {
// The conns map contains all connections we're currently handling.
// Connections are inserted as soon as they're available in the swarm
// Connections are removed from the map when the connection disconnects.
conns map[network.Conn]entry
conns map[network.Conn]*entry

addrMu sync.Mutex

Expand Down Expand Up @@ -201,7 +201,7 @@ func NewIDService(h host.Host, opts ...Option) (*idService, error) {
ProtocolVersion: cfg.protocolVersion,
ctx: ctx,
ctxCancel: cancel,
conns: make(map[network.Conn]entry),
conns: make(map[network.Conn]*entry),
disableSignedPeerRecord: cfg.disableSignedPeerRecord,
setupCompleted: make(chan struct{}),
metricsTracer: cfg.metricsTracer,
Expand Down Expand Up @@ -412,7 +412,7 @@ func (ids *idService) IdentifyWait(c network.Conn) <-chan struct{} {
close(ch)
return ch
} else {
ids.addConnWithLock(c)
e = ids.addConnWithLock(c)
}
}

Expand All @@ -421,7 +421,6 @@ func (ids *idService) IdentifyWait(c network.Conn) <-chan struct{} {
}
// First call to IdentifyWait for this connection. Create the channel.
e.IdentifyWaitChan = make(chan struct{})
ids.conns[c] = e

// Spawn an identify. The connection may actually be closed
// already, but that doesn't really matter. We'll fail to open a
Expand Down Expand Up @@ -986,12 +985,14 @@ func HasConsistentTransport(a ma.Multiaddr, green []ma.Multiaddr) bool {
}

// addConnWithLock assuems caller holds the connsMu lock
func (ids *idService) addConnWithLock(c network.Conn) {
_, found := ids.conns[c]
func (ids *idService) addConnWithLock(c network.Conn) *entry {
e, found := ids.conns[c]
if !found {
<-ids.setupCompleted
ids.conns[c] = entry{}
e = &entry{}
ids.conns[c] = e
}
return e
}

func signedPeerRecordFromMessage(msg *pb.Identify) (*record.Envelope, error) {
Expand Down
Loading