# A gotcha with fcntl file locking Today I ran into an issue with [fcntl(2)](http://linux.die.net/man/2/fcntl) file locking[^1] on Linux. A little research confirmed my fear: From ["On the Brokenness of File Locking"](https://0pointer.de/blog/projects/locking.html) by Lennart Poettering: > The worst part however is that POSIX locks are automatically released if a process calls `close()` on *any* (!) of its open file descriptors for that file. The whole post is well worth a read. [^1]: Which is what OpenJDK uses for [FileChannel#lock](http://docs.oracle.com/javase/8/docs/api/java/nio/channels/FileChannel.html#lock--). ## Page metadata URL: Published 2015-09-26, updated 2021-08-21. Tags: - JVM - Linux - old blog - programming - Unix Index: [Old blog](/old-blog).