Hi!
Some Jenkins instances of ours do log FileAlreadyExistsException-s from 
time to time:

java.nio.file.FileAlreadyExistsException: (path2onesJob)/lastSuccessful
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:88)
(..) at *hudson.Util.createSymlinkJava7*(Util.java:1122)
(..)

-Above trace mapping to 1.509.2.
Code shows "proper" deletion of symlink prior to (re)creating it:
(..)
            filesC.getMethod("*deleteIfExists*", pathC).invoke(null, path);
            Object noAttrs = 
Array.newInstance(Class.forName("java.nio.file.attribute.FileAttribute"), 
0);
            filesC.getMethod("*createSymbolicLink*", pathC, pathC, 
noAttrs.getClass()).invoke(null, path, target, noAttrs);

-Looking at that code and around,
I suspect some occasional race condition by lack of concurrency safeness:
1. thread-A deletes any existing lastSuccessful symlink (so far so good)
2. thread-B deletes it too but that is a no-op by now, given 1.
3. thread-A (re)creates the symlink (no problem yet)
4. thread-B recreates the symlink, but that throws our hereby exception, 
given 3. (problematic).

-Unless such initial deletion fails because of this:
"On some operating systems it may not be possible to remove a file when it 
is open and in use by this Java virtual machine or other programs." (*)
(*) 
http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#deleteIfExists(java.nio.file.Path)

=> Q, please -assuming the above threading hypothesis and solving it to be 
hard & risky:
would you consider adding handling of that FileAlreadyExistsException, so 
createSymlinkJava7 logs it then return true (ok)?
-Thx for sharing your ideas,
Marco.

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to