atomashpolskiy / bt

BitTorrent library and client with DHT, magnet links, encryption and more
https://atomashpolskiy.github.io/bt/
Apache License 2.0
2.41k stars 382 forks source link

AccessDeniedException keeps getting thrown inside SpringBoot request #107

Closed SaadArdati closed 5 years ago

SaadArdati commented 5 years ago

I'm sending torrent links from an external third party into my server. Springboot takes the request and downloads the torrent. However, BT keeps crashing with an AccessDeniedException without any further context. It says that Files.delete is throwing the exception which makes sense as it's the only method that can crash with such an error.

Here's my code: https://hasteb.in/aradumew.java

The error thrown is: https://hasteb.in/tameyiqu.sql

Am I doing something wrong?

The other issue on this repo says that the error has been made more verbose but that release hasn't appeared on maven in a very long time and it's not even a solution to the issue.

This stackoverflow thread mentions File.delete can cause this crash if something tries to reopen the file after it's marked to be deleted. https://stackoverflow.com/a/31608180/4327834

atomashpolskiy commented 5 years ago

I guess the underlying issue does not need a solution, because it's just a log message and does not really affect anything.

SaadArdati commented 5 years ago

the app crashes, it's not a harmless log message

atomashpolskiy commented 5 years ago

If you're referencing this issue, the message is logged here in current master and here in 1.7 release. Obviously, it's quite harmless. What makes you think that your app crashes?

SaadArdati commented 5 years ago

Perhaps the app doesn't crash, but the torrent downloading certainly ceases to function. No console logs beyond that error message and I've waited on it for a really long time. The torrent I'm testing with is like 2MB and I was able to successfully download it using Deluge.

atomashpolskiy commented 5 years ago

It's the other way around: Bt does not terminate because of the error, but rather the error happens (and the log message is printed) when Bt terminates. There may be three reasons for Bt to terminate: either the JVM process has received a termination signal from the operating system, or it was explicitly asked to shutdown/stop by the application code, or the runtime has been configured to stop when the download has completed (I think this should be your case, so check if the files have been downloaded). If you have any doubts, don't wait, check what your application is doing with jstack. Also, you don't need to stop the client explicitly, if stopWhenDownloaded() is set (there should not be any harm in doing this though, it's just not necessary).

SaadArdati commented 5 years ago

I see. I figured out the issue. The targetDirectory was set to ~/Downloads. I changed it to Downloads and the issue is resolved. The file downloaded flawlessly. Thank you.

You'll probably want to change this in the readme.md of the github page.

atomashpolskiy commented 5 years ago

Great to hear that the issue is resolved, closing now

SaadArdati commented 5 years ago

Actually, is it possible to suppress the error messages? I rely on my console for debug purposes and the errors keep spamming it.

SaadArdati commented 5 years ago

also I found another unusual bug where my download gets stuck at 98.9%. I kept the same torrent going for an hour and it never stopped

atomashpolskiy commented 5 years ago

Actually, is it possible to suppress the error messages? I rely on my console for debug purposes and the errors keep spamming it.

Bt uses slf4j, so you need to setup your logger.

also I found another unusual bug where my download gets stuck at 98.9%

Yeah, I'm aware of this. Unfortunately, I'm not sure what's causing it.

SaadArdati commented 5 years ago

Although that is unfortunate, is there a way to circumvent the issue? If there's a way to detect when it happens maybe? Temporary solutions?