olamy commented on code in PR #1799:
URL: https://github.com/apache/maven-resolver/pull/1799#discussion_r2826586935


##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java:
##########
@@ -161,9 +161,19 @@ private FileLock fileLock(FileChannel channel, boolean 
shared) throws IOExceptio
             try {
                 lock = channel.lock(0, Long.MAX_VALUE, shared);
                 break;
-            } catch (OverlappingFileLockException e) {
+            } catch (OverlappingFileLockException | IOException e) {
+                // For Unix process sun.nio.ch.UnixFileDispatcherImpl.lock0() 
is a native method that can throw
+                // IOException
+                // with message "Resource deadlock avoided"
+                // the system call level is involving fcntl() or flock()
+                // If the kernel detects that granting the lock would result 
in a deadlock
+                // (where two processes are waiting for each other to release 
locks which can happen when two processes
+                // are trying to lock the same file),
+                // it returns an EDEADLK error, which Java throws as an 
IOException.

Review Comment:
   After the wait time, the other process or thread will have released its 
lock. 
   There is similar code in the Android 
https://github.com/androidx/androidx/blob/1c55c017b56b3d702e8013a0aa9baee866ea9fb7/datastore/datastore-core/src/androidMain/kotlin/androidx/datastore/core/MultiProcessCoordinator.android.kt#L77
 
   
   and coursier 
   
https://github.com/coursier/coursier/blob/345d58581abafac56891dcbaef24ec6e79ce0fb5/modules/bootstrap-launcher/src/main/java/coursier/bootstrap/launcher/Download.java#L208
   
   as well as the comment added here.
   
   Maybe we should limit to this `if(e.getMessage().contains("Resource deadlock 
avoided"))` though. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to