F_GETLK doesn't always return lock owner
Issue #6225 describes a scenario where fcntl(F_GETLK) returns F_UNLCK even though F_SETLK declines the lock. This basically happens when one process holds a read lock while a second process waits for a write lock. Subsequent read lock requests fail, because the pending write lock blocks out new read locks to avoid write starvation.
flk_get_first_blocking_lock() is the function that determines the result of F_GETLK. For this, it only searches the list of all currently held locks. As this list contains only a read lock, it returns F_UNLCK.
To fix this, it's necessary to also search the list of pending locks to see if there is a write lock waiting.
Updated by Electric Monk over 5 years ago
- Status changed from In Progress to Closed
- % Done changed from 0 to 100
commit b584d06cf5d63c0af8a641ca543c28986ec5cf81 Author: Arne Jansen <firstname.lastname@example.org> Date: 2015-09-22T13:50:05.000Z 6253 F_GETLK doesn't always return lock owner Reviewed by: Marcel Telka <email@example.com> Reviewed by: Simon Klinkert <firstname.lastname@example.org> Approved by: Dan McDonald <email@example.com>