Commit a67b148
authored
Clean up .dll files on Windows (#493)
**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.
**DESCRIPTION OF CHANGES:** On Windows only, during startup, scan the temp dir for old instances of `AWSCRT_*aws-crt-jni.dll` and try to delete them.
**DIAGNOSIS:** We were using [File.deleteOnExit()](https://docs.oracle.com/javase/8/docs/api/java/io/File.html#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.
**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.1 parent e7ae730 commit a67b148
1 file changed
+50
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
151 | | - | |
152 | | - | |
153 | 152 | | |
154 | | - | |
155 | 153 | | |
156 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
157 | 176 | | |
158 | 177 | | |
159 | | - | |
| 178 | + | |
| 179 | + | |
160 | 180 | | |
161 | | - | |
| 181 | + | |
162 | 182 | | |
163 | 183 | | |
164 | 184 | | |
| |||
185 | 205 | | |
186 | 206 | | |
187 | 207 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | 208 | | |
192 | 209 | | |
193 | 210 | | |
| |||
236 | 253 | | |
237 | 254 | | |
238 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
239 | 280 | | |
240 | 281 | | |
241 | 282 | | |
| |||
0 commit comments