diff options
author | ftrees <58193105+ftreesmilo@users.noreply.github.com> | 2021-07-13 21:41:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-13 21:41:01 +0300 |
commit | 3b3f65afaecb88dcdbb1f342a3643343eaf22c80 (patch) | |
tree | 436e94ea8184fb162ca83bae03003bff29d51b68 /lib | |
parent | 303f61525b40898a975680ea4b60c11e29f165a8 (diff) |
fix: store.put is async and might fail (#2006)
* store.put is async and might fail
* Remove retry logic for now
Co-authored-by: John Hiesey <john@hiesey.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/torrent.js | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 62fa016..0a473ba 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1627,29 +1627,29 @@ class Torrent extends EventEmitter { if (self.destroyed) return if (hash === self._hashes[index]) { - if (!self.pieces[index]) return self._debug('piece verified %s', index) - self.pieces[index] = null - self._reservations[index] = null - self.bitfield.set(index, true) - self.store.put(index, buf, err => { - if (err) self._destroy(err) - }) - - self.wires.forEach(wire => { - wire.have(index) + if (err) { + self._destroy(err) + return + } else { + self.pieces[index] = null + self._markVerified(index) + self.wires.forEach(wire => { + wire.have(index) + }) + } + // 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() + onUpdateTick() }) - - // 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`)) + onUpdateTick() } - onUpdateTick() }) }) |