aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/server.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-04-10 19:20:26 +0800
committerFelix Lange <fjl@twurst.com>2015-04-10 19:26:27 +0800
commit145330fdf28b6d6bf3558dec0b512a5379d446f7 (patch)
treea3609b54124f0a6fcaad4dfee36e5c81ed7f9447 /p2p/server.go
parentf1d710af006d7e9ed6046ab410976bd20c1e3c97 (diff)
downloaddexon-145330fdf28b6d6bf3558dec0b512a5379d446f7.tar.gz
dexon-145330fdf28b6d6bf3558dec0b512a5379d446f7.tar.zst
dexon-145330fdf28b6d6bf3558dec0b512a5379d446f7.zip
p2p: properly decrement peer wait group counter for setup errors
Diffstat (limited to 'p2p/server.go')
-rw-r--r--p2p/server.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/p2p/server.go b/p2p/server.go
index b21b83252..d227d477a 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -344,6 +344,10 @@ func (srv *Server) dialNode(dest *discover.Node) {
glog.V(logger.Debug).Infof("Dialing %v\n", dest)
conn, err := srv.Dialer.Dial("tcp", addr.String())
if err != nil {
+ // dialLoop adds to the wait group counter when launching
+ // dialNode, so we need to count it down again. startPeer also
+ // does that when an error occurs.
+ srv.peerWG.Done()
glog.V(logger.Detail).Infof("dial error: %v", err)
return
}
@@ -356,11 +360,17 @@ func (srv *Server) Self() *discover.Node {
func (srv *Server) startPeer(fd net.Conn, dest *discover.Node) {
// TODO: handle/store session token
+
+ // Run setupFunc, which should create an authenticated connection
+ // and run the capability exchange. Note that any early error
+ // returns during that exchange need to call peerWG.Done because
+ // the callers of startPeer added the peer to the wait group already.
fd.SetDeadline(time.Now().Add(handshakeTimeout))
conn, err := srv.setupFunc(fd, srv.PrivateKey, srv.ourHandshake, dest)
if err != nil {
fd.Close()
glog.V(logger.Debug).Infof("Handshake with %v failed: %v", fd.RemoteAddr(), err)
+ srv.peerWG.Done()
return
}
conn.MsgReadWriter = &netWrapper{
@@ -371,6 +381,7 @@ func (srv *Server) startPeer(fd net.Conn, dest *discover.Node) {
if ok, reason := srv.addPeer(conn.ID, p); !ok {
glog.V(logger.Detail).Infof("Not adding %v (%v)\n", p, reason)
p.politeDisconnect(reason)
+ srv.peerWG.Done()
return
}
// The handshakes are done and it passed all checks.