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
#2168 Synchronizing extraction of pluggable transports on class to avoid... #2169
Conversation
…oid race condition in extracting file
I would consider using FileLock in LanternUtils instead, as it would solve the problem more generally and would isolate the locking to the file itself. |
Neat idea. Do you mean org.littleshoot.util.FileLockUtils ? |
No java.nio.channels.FileLock directly -- something like FileOutputStream out = new FileOutputStream(file);
try {
java.nio.channels.FileLock lock = out.getChannel().lock();
try {
// move file in here.
} finally {
lock.release();
}
} finally {
in.close();
} |
Gotcha. And this is to prevent problems when running two instances of Lantern, right? |
It's definitely a bit more verbose, but more robust I think too. |
Yeah, I'm basically thinking we just lock the flashlight file, although now that I think about it that'll just lock to the process not the thread -- maybe ignore me. |
Correct. From the Javadoc for java.nio.channels.FileLock: "File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine." |
OK, let's just go with your solution. I'm always wary of synchronizing on a class, but I can't think of anything better here. |
#2168 Synchronizing extraction of pluggable transports on class to avoid...
Thanks! |
... race condition in extracting file