glassfish icon indicating copy to clipboard operation
glassfish copied to clipboard

ManagedFile is platform dependent

Open dmatej opened this issue 2 years ago • 3 comments

After we made a quick fix of the FileLockTest in #24606 (original test just printed errors to the stdout, but did not fail), it made visible problem in ManagedFile class - it is platform dependent and the file locking mechanism generally doesn't work.

FileLockTest passes on Linux systems, now it passes also on Windows, but we had to duplicate the test so now it has different results on Windows and Linux. And now @arjantijms found that there's another failure on Mac.

FileLockTest.lockAndRenameTest:364 File renaming blocked ==> expected: <true> but was: <false>

~/which_java.sh 
/dev/stdin: Mach-O 64-bit executable arm64

uname -a
Darwin Arjans-MacBook-Pro.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64

Then we should to this:

  • Investigate if we really need the ManagedFile class and classes around that
  • Investigate if it can be fixed so the mechanism would work on all operating systems.
  • Make the decision and do the work required.

See also https://github.com/eclipse-ee4j/glassfish/pull/24623 , where we tried to avoid another test failure on one operating system.

dmatej avatar Oct 05 '23 17:10 dmatej

Just for completeness, this is a javadoc of the File.rename method:

Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.

dmatej avatar Oct 05 '23 17:10 dmatej

I have take a look at it. It seems like you guys want to use FileLock to implement a system level read-write lock. I saw it used in DomainXmlPersistence, but FileLock is system dependent. maybe we can use Unix Domain Socket to implement it? I checked it implemented in Linux, Windows and MacOS, but it requires Java 16 or above.

PatrickHuang888 avatar Oct 24 '23 04:10 PatrickHuang888

This issue has been marked as inactive and old and will be closed in 7 days if there is no further activity. If you want the issue to remain open please add a comment

github-actions[bot] avatar Oct 24 '24 00:10 github-actions[bot]

ManagedFile was deleted in #25205

dmatej avatar Nov 24 '24 15:11 dmatej