Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cleanup DHT tables cache on torrent removal #1289

Open
wants to merge 5 commits into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -390,6 +390,10 @@ WebTorrent.prototype._remove = function (torrentId, cb) {
var torrent = this.get(torrentId)
if (!torrent) return
this.torrents.splice(this.torrents.indexOf(torrent), 1)
// clear hash entity in cache to be able use pears search again
if (this.dht) {
this.dht._tables.remove(torrent.infoHash)
}
torrent.destroy(cb)
}

@@ -31,6 +31,8 @@ var uniq = require('uniq')
var utMetadata = require('ut_metadata')
var utPex = require('ut_pex') // browser exclude
var parseRange = require('parse-numeric-range')
var thunky = require('thunky')
var raf = require('random-access-file')

var File = require('./file')
var Peer = require('./peer')
@@ -1602,10 +1604,33 @@ Torrent.prototype._checkDone = function () {
}
if (!done) break
}
if (!self.done && done) {
self.done = true
self._debug('torrent done: ' + self.infoHash)
self.emit('done')
if (done) {
const done = () => {
self.done = true
self._debug('torrent done: ' + self.infoHash)
self.emit('done')
}
// flush files to be able to open after download finish
if(self._store === FSChunkStore)
{
let tasks = self.store.store.files.map(function (storeFile) {
return function (cb) {
storeFile.open(function (err, file) {
// an open error is okay because that means the file is not open
if (err) return cb(null)
file.close(() => {
storeFile.open = thunky((cb) => cb(null, raf(storeFile.path)))
cb()
})
})
}
})
parallel(tasks, done)
}
else
{
done()
}
}
self._gcSelections()

@@ -61,7 +61,7 @@
"stream-to-blob": "^1.0.0",
"stream-to-blob-url": "^2.1.0",
"stream-with-known-length-to-buffer": "^1.0.0",
"torrent-discovery": "^8.3.1",
"torrent-discovery": "^9.1.1",
"torrent-piece": "^1.1.0",
"uniq": "^1.0.1",
"unordered-array-remove": "^1.0.2",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.