Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OverlappingFileLockException #95

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion java/com/facebook/soloader/FileLocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down