From b9c817d3a733a9cfc30c7fa21255b6e82604e053 Mon Sep 17 00:00:00 2001 From: Jon Bettcher Date: Mon, 21 Mar 2022 13:45:47 -0600 Subject: [PATCH] Fix OverlappingFileLockException --- java/com/facebook/soloader/FileLocker.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/java/com/facebook/soloader/FileLocker.java b/java/com/facebook/soloader/FileLocker.java index 1434782..d61c248 100644 --- a/java/com/facebook/soloader/FileLocker.java +++ b/java/com/facebook/soloader/FileLocker.java @@ -21,6 +21,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileLock; +import java.nio.channels.OverlappingFileLockException; import javax.annotation.Nullable; public final class FileLocker implements Closeable { @@ -48,8 +49,11 @@ private void init(File lockFile, boolean tryLock) throws IOException { if (tryLock) { try { lock = mLockFileOutputStream.getChannel().tryLock(); - } catch (IOException e) { + } catch (IOException | OverlappingFileLockException e) { // Try lock can throw an IOException (EAGAIN) while lock doesn't. + // If this process already holds the lock this will throw OverlappingFileLockException as a RuntimeException. + // Ideally, this code would not try to init if the lock is held elsewhere, but this is the most + // straightforward fix for now lock = null; } } else {