Commit e436bcc3 authored by Steven Allen's avatar Steven Allen
Browse files

always remove connection from identify service map

fixes #419

Also call FullClose in a goroutine; no need to block this.

(not happy with that but I'm starting to think we need to rethink stream
closing, again...)
parent fe20b1dd
...@@ -83,7 +83,12 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { ...@@ -83,7 +83,12 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
ids.currid[c] = ch ids.currid[c] = ch
ids.currmu.Unlock() ids.currmu.Unlock()
defer close(ch) defer func() {
close(ch)
ids.currmu.Lock()
delete(ids.currid, c)
ids.currmu.Unlock()
}()
s, err := c.NewStream() s, err := c.NewStream()
if err != nil { if err != nil {
...@@ -103,16 +108,6 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { ...@@ -103,16 +108,6 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
} }
ids.responseHandler(s) ids.responseHandler(s)
ids.currmu.Lock()
_, found := ids.currid[c]
delete(ids.currid, c)
ids.currmu.Unlock()
if !found {
log.Errorf("IdentifyConn failed to find channel (programmer error) for %s", c)
}
inet.FullClose(s)
} }
func (ids *IDService) requestHandler(s inet.Stream) { func (ids *IDService) requestHandler(s inet.Stream) {
...@@ -135,12 +130,14 @@ func (ids *IDService) responseHandler(s inet.Stream) { ...@@ -135,12 +130,14 @@ func (ids *IDService) responseHandler(s inet.Stream) {
mes := pb.Identify{} mes := pb.Identify{}
if err := r.ReadMsg(&mes); err != nil { if err := r.ReadMsg(&mes); err != nil {
log.Warning("error reading identify message: ", err) log.Warning("error reading identify message: ", err)
s.Reset()
return return
} }
ids.consumeMessage(&mes, c) ids.consumeMessage(&mes, c)
log.Debugf("%s received message from %s %s", ID, log.Debugf("%s received message from %s %s", ID,
c.RemotePeer(), c.RemoteMultiaddr()) c.RemotePeer(), c.RemoteMultiaddr())
go inet.FullClose(s)
} }
func (ids *IDService) populateMessage(mes *pb.Identify, c inet.Conn) { func (ids *IDService) populateMessage(mes *pb.Identify, c inet.Conn) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment