From 35813ad939afba911efdd1a844e814dc11f7400e Mon Sep 17 00:00:00 2001 From: "andrew.shvv" Date: Thu, 16 Mar 2017 22:37:36 +0300 Subject: [PATCH] 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. --- server.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index 612d1867..fa2a40e9 100644 --- a/server.go +++ b/server.go @@ -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 }