Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2016-05-18 04:02:09 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-05-18 04:02:09 +0300
commitb7e10c5814682454b340f7d96a309a78883db2d2 (patch)
tree034f5a7a48e34e071ea70f6187ec4bb800e4f314 /lib/peer.js
parent1206c2ac5f0faba0b9d6ef97e4a566d8a87374f8 (diff)
Fix exception caused by race condition
If a peer disconnects, but the handshake they already sent hasn't been processed by the wire yet (rare!) then onHandshake could be called after the peer is destroyed. At this point self.wire is `null`, so that will get pushed into the self.swarm.wires array and cause this issue: https://github.com/feross/webtorrent/issues/792 Closes #792.
Diffstat (limited to 'lib/peer.js')
-rw-r--r--lib/peer.js5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/peer.js b/lib/peer.js
index fcd296d..01a3935 100644
--- a/lib/peer.js
+++ b/lib/peer.js
@@ -155,8 +155,11 @@ Peer.prototype.onConnect = function () {
Peer.prototype.onHandshake = function (infoHash, peerId) {
var self = this
if (!self.swarm) return // `self.swarm` not set yet, so do nothing
+ if (self.destroyed) return
- if (self.swarm.destroyed) return self.destroy(new Error('swarm already destroyed'))
+ if (self.swarm.destroyed) {
+ return self.destroy(new Error('swarm already destroyed'))
+ }
if (infoHash !== self.swarm.infoHash) {
return self.destroy(new Error('unexpected handshake info hash for this swarm'))
}