-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
WebTorrent.remove method removes correct torrent and, incorrectly, the last torrent #2767
Comments
LostBeard
added a commit
to LostBeard/webtorrent
that referenced
this issue
Mar 27, 2024
To reproduce the bugThe below code can be pasted into a website console to test for the bug. The example uses the jsdelivr site to load the The magnet links are Big Buck Bunny and Sintel from the free magnet links page. Steps to reproduce: var WebTorrentModule = await import('https://cdn.jsdelivr.net/gh/webtorrent/webtorrent/dist/webtorrent.min.js');
var WebTorrent = WebTorrentModule.default;
console.log('WebTorrent.VERSION', WebTorrent.VERSION);
// prints "WebTorrent.VERSION 2.2.0"
var client = new WebTorrent();
// Sintel and Big Buck Bunny magnets (trimmed to just hashes for brevity)
var magnets = [ '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 removed
await client.remove(magnets[0]);
console.log('torrents.length', client.torrents.length);
// prints "torrents.length 0" due to bug
// should print "torrents.length 1" (Edited to simplify example code) |
SilentBot1
added a commit
that referenced
this issue
May 31, 2024
* Added WebTorrent add and remove events and docs update * Fix for issue #2767 WebTorrent.remove bug * Update index.js Co-authored-by: Brad Marsden <[email protected]> * Update index.js Co-authored-by: Brad Marsden <[email protected]> --------- Co-authored-by: Brad Marsden <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: