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>2017-02-03 03:22:50 +0300
committerFeross Aboukhadijeh <feross@feross.org>2017-02-03 03:22:50 +0300
commit6d5ff7ab06541847f86819825fe229516148b26e (patch)
tree41e247539b44cf9e139570b2df1e0cd996040e32 /lib/torrent.js
parent720c0b951c6d28e8f79f1b641f9cce8a8e3df707 (diff)
Be more defensive: prevent code from running after destroy
Diffstat (limited to 'lib/torrent.js')
-rw-r--r--lib/torrent.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 0f6b891..ab2dcda 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -587,9 +587,14 @@ Torrent.prototype._verifyPieces = function () {
parallelLimit(self.pieces.map(function (_, index) {
return function (cb) {
if (self.destroyed) return cb(new Error('torrent is destroyed'))
+
self.store.get(index, function (err, buf) {
+ if (self.destroyed) return cb(new Error('torrent is destroyed'))
+
if (err) return process.nextTick(cb, null) // ignore error
sha1(buf, function (hash) {
+ if (self.destroyed) return cb(new Error('torrent is destroyed'))
+
if (hash === self._hashes[index]) {
if (!self.pieces[index]) return
self._debug('piece verified %s', index)
@@ -1523,6 +1528,8 @@ Torrent.prototype._request = function (wire, index, hotswap) {
// TODO: might need to set self.pieces[index] = null here since sha1 is async
sha1(buf, function (hash) {
+ if (self.destroyed) return
+
if (hash === self._hashes[index]) {
if (!self.pieces[index]) return
self._debug('piece verified %s', index)