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
path: root/lib
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2017-02-03 03:18:12 +0300
committerFeross Aboukhadijeh <feross@feross.org>2017-02-03 03:18:12 +0300
commit720c0b951c6d28e8f79f1b641f9cce8a8e3df707 (patch)
treec3a82051912dd5c04823b3fc7e3bda1ca19ecd1f /lib
parent4ca5c9afc34dce08b8e4b1d68fd33425218ac767 (diff)
Fix "Cannot read property 'complete' of null"
Fixes: https://github.com/feross/webtorrent/issues/1022 We also check `self.destroyed` since `torrent.destroy()` could have been called in the `torrent.on('done')` handler, triggered by `_checkDone()`.
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index a2c6c57..0f6b891 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -1537,7 +1537,9 @@ Torrent.prototype._request = function (wire, index, hotswap) {
wire.have(index)
})
- if (self._checkDone()) self.discovery.complete()
+ // We also check `self.destroyed` since `torrent.destroy()` could have been
+ // called in the `torrent.on('done')` handler, triggered by `_checkDone()`.
+ if (self._checkDone() && !self.destroyed) self.discovery.complete()
} else {
self.pieces[index] = new Piece(piece.length)
self.emit('warning', new Error('Piece ' + index + ' failed verification'))