Skip to content

Commit 74bfbc0

Browse files
authored
Catch IOException with message "Resource deadlock avoided" which can happen on Unix level when multiple process try to lock same file (#1799)
* Catch IOException with message "Resource deadlock avoided" which can happen on Unix level when multiple process try to lock same file Signed-off-by: Olivier Lamy <olamy@apache.org> * spotless Signed-off-by: Olivier Lamy <olamy@apache.org> --------- Signed-off-by: Olivier Lamy <olamy@apache.org>
1 parent 1020f3e commit 74bfbc0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,19 @@ private FileLock fileLock(FileChannel channel, boolean shared) throws IOExceptio
161161
try {
162162
lock = channel.lock(0, Long.MAX_VALUE, shared);
163163
break;
164-
} catch (OverlappingFileLockException e) {
164+
} catch (OverlappingFileLockException | IOException e) {
165+
// For Unix process sun.nio.ch.UnixFileDispatcherImpl.lock0() is a native method that can throw
166+
// IOException
167+
// with message "Resource deadlock avoided"
168+
// the system call level is involving fcntl() or flock()
169+
// If the kernel detects that granting the lock would result in a deadlock
170+
// (where two processes are waiting for each other to release locks which can happen when two processes
171+
// are trying to lock the same file),
172+
// it returns an EDEADLK error, which Java throws as an IOException.
173+
// Read another comment from
174+
// https://github.com/bdeployteam/bdeploy/blob/7c04e7228d6d48b8990e6703a8d476e21024c639/bhive/src/main/java/io/bdeploy/bhive/objects/LockableDatabase.java#L57
165175
if (attempts <= 0) {
166-
throw new IOException(e);
176+
throw (e instanceof IOException) ? (IOException) e : new IOException(e);
167177
}
168178
try {
169179
Thread.sleep(50L);

0 commit comments

Comments
 (0)