Our application is written in Java and we’re attempting to control updates using the update lock. However, after some testing by one of our developers and a support ticket discussion with balena, we found that the JVM’s FileChannel creates POSIX locks while the OS update service only checks for flocks. For example:
FileChannel.open(LOCKFILE_PATH, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW);
root@d7c3179:/tmp/balena# lslocks
COMMAND PID TYPE SIZE MODE M START END PATH
java 1 POSIX WRITE 0 0 0 /tmp/balena/updates.lock
We can create an flock using a child process or through JNI/JNA native call, but it would be nice if the process was more JVM friendly and if it was consistent between application updates (checks for file existence) and OS updates (checks for an flock).
We’ll probably move forward with a JNA native call to create a flock for now. Would it be possible to have a locking endpoint on the Supervisor? Then it would just be an API call that should work in any language. That is, don’t depend on file locking at all but build the mechanism into the Supervisor itself. It might also allow for more lock metadata such as who holds the lock so an application could check if it still holds the lock even if the process crashes and restarts.