-
Notifications
You must be signed in to change notification settings - Fork 42
Clean up .dll files on Windows #493
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
Conversation
| // for old instances of the .dll and try to delete them. If another | ||
| // process is still using the .dll, the delete will fail, which is fine. | ||
| String os = getOSIdentifier(); | ||
| if (os == "windows") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like platform id shouldn't be a string, but that's a larger change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.equals()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another great reason to make it not-a-string!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started making it not-a-string but it was turning into a big refactor so going with .equals() as suggested by Dombo
Update to latest aws-crt. Contains [fix](awslabs/aws-crt-java#493) that, on startup, deletes any .dll files it finds from previous runs of the library.
Update to latest aws-crt. Contains [fix](awslabs/aws-crt-java#493) that, on startup, deletes any .dll files it finds from previous runs of the library.
ISSUE: On Windows, the .dll file extracted to the temp directory was never being deleted. And repeated runs of the program were filling the disk with old .dll files.
DIAGNOSIS: We were using File.deleteOnExit() to clean up the shared lib, which is working OK on other platforms, but not on Windows. On Windows, files cannot be deleted while they're in use, and it appears that Java doesn't try to "unload" the .dll, so it's apparently impossible for a Java process to delete a .dll that it's using.
I did an experiment with a dead-simple JNI library. I simply loaded it, and called
File.deleteOnExit(). That .dll didn't get deleted either. So it's not just a problem with our .dll being very complex.DESCRIPTION OF CHANGES: On Windows only, during startup, scan the temp dir for old instances of
AWSCRT_*aws-crt-jni.dlland try to delete them.SIDE-NOTE:
I realized that on non-Windows platforms, the shared-lib won't be deleted on exit if Java dies suddenly (crash in C, OS terminated process, etc). But on non-Windows platforms you can delete the shared-lib from disk immediately after loading it, you don't need to wait until the process exits. I did experiments on Mac and this works. But I left it out of this PR because this is an emergency fix for windows and I don't want to introduce non-necessary changes.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.