Open rburch314 opened 10 years ago
Same problem here. Discovered it different way, though: my client jvm wouldn't exit after done with downloading torrent because of this lingering non-daemon bt-peer thread.
This thread hangs here: https://github.com/mpetazzoni/ttorrent/blob/fce1fc7990ee06b0b3968b7682166d0187cc78c7/core/src/main/java/com/turn/ttorrent/client/peer/PeerExchange.java#L294
Seems like that even though 'stop' flag of IncomingThread is being correctly set to true, thread never wakes up from select(), because no timeout was set. Well, I guess, unless some other peer tries to connect to mine.
Nice catch @alepar
I am using the ttorrent library to distribute a file from a "controller" machine to a bunch of "worker" machines and I have recently discovered that I a building up a bunch of bt-peer threads.
To give a high-level flow of my process the "controller" takes in a job and distributes the work out to a bunch of "worker" machines. Over the course of the job the "controller" will be updating a file that at the end of the job needs to be distributed out to the "worker" machines, which is where ttorrent comes in. To perform this distribution the "controller" generates a new .torrent file and starts up 4 Clients to act as seeders for the file (it will also stop any old seeder clients from the previous job). The .torrent file is distributed to the workers and they start up a Client to download and seed the file.
With my recent testing I encountered an issue with the "controller" running out of memory and after taking a jstack I found that I had accumulated ~700 bt-peer threads after running 20 or so jobs. Here is a sample of the jstack to show the state of the bt-peer threads.
Now to be honest I am not sure if I am missing a step when closing down a Client, but I am suspicious that the issue is caused by the PeerExchange not interrupting the IncomingThread and OutgoingThread when it is closed. I also noticed that the Client code only closes the "connected" collection of peers and not the "peers" collection of peers so as you will see below I even tried closing those to see if it fixed my issue, but to no avail. To that end here is the code that stops the old clients and starts up new ones.
Would really appreciate any insight you might have to what I am doing wrong or if this is an actual issue, thanks.