p2p: fix goroutine leak for invalid peers
The deflect logic called Disconnect on the peer, but the peer never ran and wouldn't process the disconnect request.
This commit is contained in:
parent
5110f80bba
commit
22ee366ed6
@ -351,19 +351,21 @@ func (srv *Server) startPeer(conn net.Conn, dest *discover.Node) {
|
|||||||
srvlog.Debugf("Encryption Handshake with %v failed: %v", conn.RemoteAddr(), err)
|
srvlog.Debugf("Encryption Handshake with %v failed: %v", conn.RemoteAddr(), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ourID := srv.ntab.Self()
|
ourID := srv.ntab.Self()
|
||||||
p := newPeer(conn, srv.Protocols, srv.Name, &ourID, &remoteID)
|
p := newPeer(conn, srv.Protocols, srv.Name, &ourID, &remoteID)
|
||||||
if ok, reason := srv.addPeer(remoteID, p); !ok {
|
if ok, reason := srv.addPeer(remoteID, p); !ok {
|
||||||
p.Disconnect(reason)
|
srvlog.DebugDetailf("Not adding %v (%v)\n", p, reason)
|
||||||
|
p.politeDisconnect(reason)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
srvlog.Debugf("Added %v\n", p)
|
||||||
|
|
||||||
if srv.newPeerHook != nil {
|
if srv.newPeerHook != nil {
|
||||||
srv.newPeerHook(p)
|
srv.newPeerHook(p)
|
||||||
}
|
}
|
||||||
p.run()
|
discreason := p.run()
|
||||||
srv.removePeer(p)
|
srv.removePeer(p)
|
||||||
|
srvlog.Debugf("Removed %v (%v)\n", p, discreason)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) addPeer(id discover.NodeID, p *Peer) (bool, DiscReason) {
|
func (srv *Server) addPeer(id discover.NodeID, p *Peer) (bool, DiscReason) {
|
||||||
@ -381,14 +383,11 @@ func (srv *Server) addPeer(id discover.NodeID, p *Peer) (bool, DiscReason) {
|
|||||||
case id == srv.ntab.Self():
|
case id == srv.ntab.Self():
|
||||||
return false, DiscSelf
|
return false, DiscSelf
|
||||||
}
|
}
|
||||||
srvlog.Debugf("Adding %v\n", p)
|
|
||||||
srv.peers[id] = p
|
srv.peers[id] = p
|
||||||
return true, 0
|
return true, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes peer: sending disconnect msg, stop peer, remove rom list/table, release slot
|
|
||||||
func (srv *Server) removePeer(p *Peer) {
|
func (srv *Server) removePeer(p *Peer) {
|
||||||
srvlog.Debugf("Removing %v\n", p)
|
|
||||||
srv.lock.Lock()
|
srv.lock.Lock()
|
||||||
delete(srv.peers, *p.remoteID)
|
delete(srv.peers, *p.remoteID)
|
||||||
srv.lock.Unlock()
|
srv.lock.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user