shashank created CAMEL-27322:
--------------------------------

             Summary: camel-file - a FileLockClusterView follower in the same 
JVM releases the leader's file lock, so a member in another JVM can become a 
second leader
                 Key: CAMEL-27322
                 URL: https://issues.apache.org/jira/browse/CAMEL-27322
             Project: Camel
          Issue Type: Bug
          Components: camel-file
            Reporter: shashank
            Assignee: shashank


h3. What happens

{{FileLockClusterView.acquireLock}} opens a new {{RandomAccessFile}} on the 
lock file and calls {{tryLock}}. When another view of the same JVM holds the 
lock, the JDK throws {{OverlappingFileLockException}} and the new channel is 
closed. The file locks are locks of the process (POSIX fcntl on Linux and 
macOS): closing any channel of the file releases all the locks of the process 
on it ({{FileLock}} javadoc). The leader view stays LEADER and its {{FileLock}} 
still says it is valid, but the file is no longer locked at OS level, so a 
member in another JVM can take the lock and become LEADER too.

The follower only tries the lock when the leader's heartbeat is stale (a GC 
pause or a blocking NFS call of the leader) or the data file is empty (cold 
start), which is when the lock is needed. Several CamelContexts with a 
{{FileLockClusterService}} on the same root in one JVM is a supported setup 
(the camel-master failover tests use it).

h3. How to reproduce

Two CamelContexts in one JVM with a {{FileLockClusterService}} on one root, 
plus a member in another JVM. Stall the leader's checks so its heartbeat gets 
stale: the follower in the same JVM tries the lock and closes its channel, an 
external fcntl probe then acquires the lock while view 1 is LEADER, and the 
member in the other JVM becomes LEADER as well.

Found with a TLA+ model of the file lock cluster view.

h3. Fix

A JVM-wide registry of the lock files that a view holds or is trying: a view 
does not open a lock file that another view of its JVM has registered; the 
entry is removed after the lock is released and the files are closed.

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to