You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What operating system, Node.js, and npm version?
Browser, Chrome 64bit, Windows 10
What happened?
(client is WebTorrent instance)
Calling client.remove(torrent.infoHash) with a valid torrent will remove that torrent but also remove the last torrent in client.torrents also.
The reason is:
client.remove() calls client_remove() where the below line is used without checking if the this.torrents.indexOf(torrent) returns -1, which would be fine if client._remove() was not called again by torrent._destroy() when it (_remove) calls torrent.destroy().
The below code can be pasted into a website console to test for the bug. The example uses the jsdelivr site to load the webtorrent.min.js in this GitHub repo's dist folder.
The magnet links are Big Buck Bunny and Sintel from the free magnet links page.
Steps to reproduce:
varWebTorrentModule=awaitimport('https://cdn.jsdelivr.net/gh/webtorrent/webtorrent/dist/webtorrent.min.js');varWebTorrent=WebTorrentModule.default;console.log('WebTorrent.VERSION',WebTorrent.VERSION);// prints "WebTorrent.VERSION 2.2.0"varclient=newWebTorrent();// Sintel and Big Buck Bunny magnets (trimmed to just hashes for brevity)varmagnets=['magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10','magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c'];client.add(magnets[0]);client.add(magnets[1]);console.log('torrents.length',client.torrents.length);// prints "torrents.length 2"// calling the below line will cause both the specified torrent and then the last torrent in client.torrents to be removedawaitclient.remove(magnets[0]);console.log('torrents.length',client.torrents.length);// prints "torrents.length 0" due to bug// should print "torrents.length 1"
What version of this package are you using?
2.2.0
What operating system, Node.js, and npm version?
Browser, Chrome 64bit, Windows 10
What happened?
(client is WebTorrent instance)
Calling
client.remove(torrent.infoHash)
with a valid torrent will remove that torrent but also remove the last torrent in client.torrents also.The reason is:
client.remove() calls client_remove() where the below line is used without checking if the
this.torrents.indexOf(torrent)
returns -1, which would be fine if client._remove() was not called again by torrent._destroy() when it (_remove) calls torrent.destroy().webtorrent/index.js
Line 414 in ff83504
The code that causes allows the issue:
index.js (WebTorrent)
webtorrent/index.js
Lines 402 to 419 in ff83504
torrent.js
webtorrent/lib/torrent.js
Lines 748 to 760 in ff83504
What did you expect to happen?
I expected only 1 torrent to be removed.
Are you willing to submit a pull request to fix this bug?
Yes. I have a pull request ready.
The text was updated successfully, but these errors were encountered: