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

Can't add same torrent twice #1664

Closed
zella opened this issue Jul 5, 2019 · 4 comments
Closed

Can't add same torrent twice #1664

zella opened this issue Jul 5, 2019 · 4 comments

Comments

@zella
Copy link

@zella zella commented Jul 5, 2019

What version of WebTorrent?
v0.104.0

What operating system and Node.js version?
ubuntu 16, node v12.2.0

What did you expect to happen?

'torrent' callback should call 2 times, when I add torrent -> remove it -> add same torrent

What actually happened?

'torrent' callback calls 1 times

Code

const WebTorrent = require('webtorrent');

const client = new WebTorrent();

client.add("08ada5a7a6183aae1e09d831df6748d566095a10");

client.on('torrent', function (torrent) {
    torrent.deselect(0, torrent.pieces.length - 1, false);
    console.log("Torrent ready");
});

setTimeout(function () {
    client.remove('08ada5a7a6183aae1e09d831df6748d566095a10');
}, 5000);

setTimeout(function () {
    client.add("08ada5a7a6183aae1e09d831df6748d566095a10");
}, 10000);

But, when I change values from 5000 to 2000, 10000 to 4000, torrent callback calls twice as expected. Always reproduced on my machine.

@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented Jul 20, 2019

Hi @zella

I'm using WebTorrent version 0.105.0 and NodeJS version 10.16.0 on Windows 10 1903 and have ran the example code provided and have been able to replicate the issue.

image

The torrent event only fires once the metadata for the torrent has been determined and downloaded, it would be expected that lower values leaves the possibility for the metadata to not be downloaded before being deleted, causing the event to not be fired but not the opposite way around as you've described.

Could you please run the following example code and provide me the results?

var Webtorrent = require('webtorrent')
var client = new Webtorrent()

client.on('torrent', (torrent)=>{
    console.log(`Torrent ${torrent.infoHash} has been added!`)
})

setTimeout(()=>{
    var torrent = client.add('magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F')
    torrent.on('ready', ()=>{
        torrent.deselect(0, (torrent.pieces.length-1), 0)
        console.log("Torrent 1 ready!")
    })
}, 0)

setTimeout(()=>{
    client.torrents[0].destroy()
    console.log("Torrent 1 destroyed!")
}, 2000)

setTimeout(()=>{
    var torrent = client.add('magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F')
    torrent.on('ready', ()=>{
        torrent.deselect(0, (torrent.pieces.length-1), 0)
        console.log("Torrent 2 ready!")
    })
}, 3000)

setTimeout(()=>{
    client.torrents[0].destroy()
    console.log("Torrent 2 destroyed!")
}, 5000)

Kind regards
Brad

@zella

This comment has been minimized.

Copy link
Author

@zella zella commented Jul 23, 2019

@SilentBot1 Hi. Stable result (0.104.0, 0.105.0):

Torrent 08ada5a7a6183aae1e09d831df6748d566095a10 has been added!
Torrent 1 ready!
Torrent 1 destroyed!
Torrent 08ada5a7a6183aae1e09d831df6748d566095a10 has been added!
Torrent 2 ready!
Torrent 2 destroyed!
@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented Jul 23, 2019

Hi @zella

It sounds like in your example WebTorrent was verifying a previous download of the infohash provided in the example code you provided.

Additionally, you call client.add before you add the `client.on('torrent' callback meaning the first torrent you add won't have all it's pieces deselected, meaning for the first 5 seconds, the torrent is downloading.

I would try clearing your WebTorrent temp folder and trying your example again after updating the code.

Hope this helps!

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Sep 10, 2019

Using setTimeout in this way is bound to be unreliable. You should not attempt to remove a torrent until the torrent's 'metadata' event fires, or the client's 'torrent' event fires.

@feross feross closed this Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.