[POSIX] Use flock instead of fcntl#973
Merged
Merged
Conversation
AlCutter
approved these changes
Jun 2, 2026
AlCutter
approved these changes
Jun 2, 2026
BSD flock locks are associated with the open file description rather than the PID, which prevents different file descriptors in the same process from concurrently acquiring the lock. This avoids a silent-release vulnerability where closing any file descriptor to the lock file in the process immediately drops the lock for all other descriptors. This doesn't fix any immediate known issues. However, it does make things less brittle. Should we change which files are written from different goroutines in the future, this will protect against multiple workers ignoring each other's locks. It also avoids a risk that a library user could create 2 instances of a POSIX storage backed by the same directory. Previously these would have ignored each other's locks, but now they will respect them.
d978112 to
5a1a561
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BSD flock locks are associated with the open file description rather than the PID, which prevents different file descriptors in the same process from concurrently acquiring the lock. This avoids a silent-release vulnerability where closing any file descriptor to the lock file in the process immediately drops the lock for all other descriptors.
This doesn't fix any immediate known issues. However, it does make things less brittle. Should we change which files are written from different goroutines in the future, this will protect against multiple workers ignoring each other's locks.
It also avoids a risk that a library user could create 2 instances of a POSIX storage backed by the same directory. Previously these would have ignored each other's locks, but now they will respect them.