Skip to content

Commit

Permalink
Handle OverlappingFileLockException in FileLock (#4335)
Browse files Browse the repository at this point in the history
I've been getting exceptions such as these lately, using Mill `0.12.5`:
```text
An unexpected error occurred java.nio.channels.OverlappingFileLockException
java.base/sun.nio.ch.FileLockTable.checkList(FileLockTable.java:229)
java.base/sun.nio.ch.FileLockTable.add(FileLockTable.java:123)
java.base/sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1522)
java.base/java.nio.channels.FileChannel.tryLock(FileChannel.java:1360)
mill.main.client.lock.FileLock.tryLock(FileLock.java:21)
mill.runner.MillMain$.withOutLock(MillMain.scala:447)
mill.runner.MillMain$.$anonfun$main0$9(MillMain.scala:247)
mill.runner.MillMain$.$anonfun$main0$9$adapted(MillMain.scala:225)
mill.runner.Watching$.watchLoop(Watching.scala:29)
mill.runner.MillMain$.$anonfun$main0$8(MillMain.scala:277)
mill.runner.MillMain$.$anonfun$main0$8$adapted(MillMain.scala:213)
scala.util.Using$.resource(Using.scala:296)
```

This ought to fix them.
  • Loading branch information
alexarchambault authored Jan 16, 2025
1 parent a44bafc commit 881c140
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main/client/src/mill/main/client/lock/FileLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.OverlappingFileLockException;

class FileLock extends Lock {

Expand All @@ -18,7 +19,13 @@ public Locked lock() throws Exception {
}

public TryLocked tryLock() throws Exception {
return new FileTryLocked(chan.tryLock());
java.nio.channels.FileLock lock = null;
try {
lock = chan.tryLock();
} catch (OverlappingFileLockException ex) {
// file already locked by this JVM
}
return new FileTryLocked(lock);
}

public boolean probe() throws Exception {
Expand Down

0 comments on commit 881c140

Please sign in to comment.