frostwire / frostwire-jlibtorrent

A swig Java interface for libtorrent by the makers of FrostWire. Develop libtorrent based apps with the joy of coding in Java.
http://www.frostwire.com
MIT License
446 stars 137 forks source link

App stop responding some times , if SessionManager.fetchmagnet is called. #140

Closed mianharisali closed 7 years ago

mianharisali commented 7 years ago

This is really weird behaviour , we have 2 apps based on Jlibtorrent. if we call SessionManager.fetchmagnet immediately after creating the session , the app stop responding. if we use the following code it works fine.

    private byte[] fetchMagnet(String uri)
    {
        final CountDownLatch signal = new CountDownLatch(1);

        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                long nodes = torrentSession.stats().dhtNodes();
                // wait for at least 10 nodes in the DHT.
                if (nodes >= 10) {
                    System.out.println("DHT contains " + nodes + " nodes");
                    signal.countDown();
                    timer.cancel();
                }
            }
        }, 0, 1000);

        //System.out.println("Waiting for nodes in DHT (10 seconds)...");
        boolean r=false;

        try
        {
             r= signal.await(30, TimeUnit.SECONDS);
        }catch(Exception e)
        {

        }

        if (!r) {
            System.out.println("DHT bootstrap timeout");
            return null;
        }

        //System.out.println("Fetching the magnet uri, please wait...");
        byte[] data = torrentSession.fetchMagnet(uri, 30000);

        if (data != null) {
            return data;
            //System.out.println(Entry.bdecode(data));
        } else {
            return null;
            //System.out.println("Failed to retrieve the magnet");
        }
    }
aldenml commented 7 years ago

Is this torrentSession the same instance of SessionManager? Can you link me to reproducible small program that I can test?

mianharisali commented 7 years ago

yes , same instance. it occurs randomly , some time it works some time it stop responding. on our old app some users complained that app was stuck at getting metadata , and we were not able to find the issue , then when were developing our 2nd app , we encountered that issue.

we still cannot reproduce the issue , it occurs randomly. but i will try to reproduce it and send you sample.

mianharisali commented 7 years ago

@aldenml sorry for this issue , it seems it was my fault. i was calling fetch magnet with 30000 seconds timeout. and if there are no peers it was waiting for timeout and stopped fetching other magnets. 1 question , it seems like it can fetch 1 magnet at a moment , is it supposed to work this way.? because if 1 fetch 2 magnets it waits for the 1st one to be fetched and then fetches the 2nd one.

for now i use new session to fetch magnet and other for downloading. fetching in same session causes too many problems.

aldenml commented 7 years ago

I'm closing this issue because it's very old, but feel free to reopen if you can provide more info, you should be able to fetch more than one magnet at a time. Also, you may want to fine tune settings_pack.int_types.active_limit with a reasonable high value.