Skip to content

Windows Locked Files

Fr Jeremy Krieg edited this page Apr 8, 2020 · 5 revisions

When running on Windows, sometimes users encounter errors with locked files. The Windows file system, unlike other platforms such as macOS and Linux, results in some situations which cause these errors.

Much work has been made in Bnd/Bndtools to find and resolve all such issues in our codebase. During this work, we have encountered other Eclipse plugins which hold files open which Bnd/Bndtools needs to write such as jar files.

Please use the File Leak Detector to identify which code may be holding open files to assist in resolving any such issues.

Eclipse

The file leak detector can be used inside Eclipse. The downloaded JAR from the site should be added as an agent. This requires changing eclipse.ini to add a new line after -vmargs

-vmargs
-javaagent:file-leak-detector-X.XX-jar-with-dependencies.jar=strong,dumpatshutdown

You can find eclipse.ini in the same directory as eclipse.exe, for example, c:\Users\micro\eclipse\java-oxygen\eclipse.

You should then start Eclipse from the command line and redirect the output to a file. Once you run into the problem, quit. This will dump the open files. Can be quite surprisingly large. You can send them to [email protected] to be analyzed.

Using File Leak Detector's built-in HTTP support

As an alternative to dumping the output to a file, you can also use File Leak Detector's built-in HTTP server. This allows you to get a snapshot of open files at any given time without having to shut down Eclipse. It means you can also have it running all the time in the background just in case you come across a file locking issue.

Use the following in eclipse.ini:

-vmargs
-javaagent:file-leak-detector-X.XX-jar-with-dependencies.jar=strong,http=19999

Then start Eclipse. If you open a browser and browse to http://localhost:19999/, you will see a current snapshot of open files and the line code that opened them. When you come across a file locking problem, browse to this page, save its contents and send the results (zipped) to [email protected] to be analyzed.

Temporary Solutions

You can set the property -x-overwritestrategy in cnf/build.bnd

    classic                         default, as today
    delay                           try, if fail, wait 500 ms, and retry 10 times.
    gc                              do a garbage collection cycle
    disposable-names                use a tmp name and link from real name
    windows-only-disposable-names   same as previous, but only on windows

First try:

-x-overwritestrategy=gc

If you still see it:

-x-overwritestrategy=windows-only-disposable-names   
Clone this wiki locally