Skip to content

Commit

Permalink
Merge pull request #49 from ipfs/fix/id-hang
Browse files Browse the repository at this point in the history
close wait channel in all cases, not just success
  • Loading branch information
whyrusleeping committed May 15, 2016
2 parents ea5428f + 6dc5e19 commit e9edd9b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
<-wait // already identifying it. wait for it.
return
}
ids.currid[c] = make(chan struct{})
ch := make(chan struct{})
ids.currid[c] = ch
ids.currmu.Unlock()

defer close(ch)

s, err := c.NewStream()
if err != nil {
log.Debugf("error opening initial stream for %s: %s", ID, err)
Expand All @@ -97,16 +100,14 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
ids.ResponseHandler(s)

ids.currmu.Lock()
ch, found := ids.currid[c]
_, found := ids.currid[c]
delete(ids.currid, c)
ids.currmu.Unlock()

if !found {
log.Debugf("IdentifyConn failed to find channel (programmer error) for %s", c)
return
}

close(ch) // release everyone waiting.
}

func (ids *IDService) RequestHandler(s inet.Stream) {
Expand Down

0 comments on commit e9edd9b

Please sign in to comment.