server: fix panic when error occures on peer intialization (#163)
If an error occurs during, peer initialization then 'p' is nil. This may cause a panic while accessing the peer's member variables. To avoid such panics, we now omit the call to `p.Disconnect` and also directly access the `connmgr.ConReq` variable if it's non-nil.
This commit is contained in:
parent
d0509955a7
commit
35813ad939
@ -449,10 +449,9 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, inbound
|
|||||||
p, err := newPeer(conn, connReq, s, peerAddr, inbound)
|
p, err := newPeer(conn, connReq, s, peerAddr, inbound)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
srvrLog.Errorf("unable to create peer %v", err)
|
srvrLog.Errorf("unable to create peer %v", err)
|
||||||
if p.connReq != nil {
|
if connReq != nil {
|
||||||
s.connMgr.Remove(p.connReq.ID())
|
s.connMgr.Remove(connReq.ID())
|
||||||
}
|
}
|
||||||
p.Disconnect()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user