network: fix unregistration on peer Disconnect

It should always signal to the server, not duplicating this send and not
missing it like it happened in the Server.run().
This commit is contained in:
Roman Khimov 2020-01-15 17:08:08 +03:00
parent 907a236285
commit f39d5d5a10

View file

@ -109,7 +109,6 @@ func (p *TCPPeer) handleConn() {
} }
} }
} }
p.server.unregister <- peerDrop{p, err}
p.Disconnect(err) p.Disconnect(err)
} }
@ -171,7 +170,6 @@ func (p *TCPPeer) StartProtocol() {
} }
} }
if err != nil { if err != nil {
p.server.unregister <- peerDrop{p, err}
timer.Stop() timer.Stop()
p.Disconnect(err) p.Disconnect(err)
return return
@ -284,6 +282,7 @@ func (p *TCPPeer) Done() chan error {
// Disconnect will fill the peer's done channel with the given error. // Disconnect will fill the peer's done channel with the given error.
func (p *TCPPeer) Disconnect(err error) { func (p *TCPPeer) Disconnect(err error) {
p.server.unregister <- peerDrop{p, err}
p.conn.Close() p.conn.Close()
select { select {
case p.done <- err: case p.done <- err: