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:
andrew.shvv 2017-03-16 22:37:36 +03:00 committed by Olaoluwa Osuntokun
parent d0509955a7
commit 35813ad939

View File

@ -449,10 +449,9 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, inbound
p, err := newPeer(conn, connReq, s, peerAddr, inbound)
if err != nil {
srvrLog.Errorf("unable to create peer %v", err)
if p.connReq != nil {
s.connMgr.Remove(p.connReq.ID())
if connReq != nil {
s.connMgr.Remove(connReq.ID())
}
p.Disconnect()
return
}