From 889f796748911a46f011812caa250d23abca81d5 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 2 Nov 2016 15:19:02 -0700 Subject: [PATCH] peer: fix race condition - open emitted after peer.close(). --- lib/net/peer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/net/peer.js b/lib/net/peer.js index 932576bc..5c88b349 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -290,6 +290,12 @@ Peer.prototype.open = co(function* open() { return; } + // The peer may have been killed before + // the handshake finished. In this case, + // do not emit `open`. + if (this.destroyed) + return; + // Finally we can let the pool know // that this peer is ready to go. this.emit('open');