-
Notifications
You must be signed in to change notification settings - Fork 574
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
caching resource has race condition in case of multiple JVMs #182
Comments
|
"waiting that files are at least 1 second old" seems not working as both JVMs fall in the earlier if branch. The test code import org.bytedeco.javacpp.opencv_core;
public class CacheTest {
public static void main(String args[]) throws Exception {
System.setProperty("org.bytedeco.javacpp.logger.debug", "true");
opencv_core.Mat mat = new opencv_core.Mat(200, 100, opencv_core.CV_8UC3);
System.out.printf("%d %d\n", mat.cols(), mat.rows());
}
} The output of JVM1
The output of JVM2
You can found that both JVMs try to write
|
I see, so we'd have to move that check before calling extractResources()... |
Actually, that won't help much. I think this is the answer: |
So would you mind detailing how File.createNewFile() can be of help to solve this problem? |
Not sure yet, but we need something like this. |
It helps if we lock L397 to L435 of Loader.java using something like FileLock, and the required lock file could be put under |
Good idea! I was under the impression that we wouldn't have the required API in Android for something like that, but it appears we do: https://developer.android.com/reference/java/nio/channels/FileLock.html Could you send a PR for that? |
close as PR was merged |
extractResource didn't consider the race condition, so the target resource file like
~/.javacpp/cache/opencv-3.2.0-1.3-linux-x86_64.jar/org/bytedeco/javacpp/linux-x86_64/libjniopencv_core.so
could be corrupted when multiple JVMs try to write the same file.One can easily reproduce this by
and see error likes
or
Possible (but not good) solutions:
Any better ideas?
The text was updated successfully, but these errors were encountered: