Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/go/internal/lockedfile: clean *.lock files #30409
What version of Go are you using (
Deleting lockfiles is subtle, and it would be very easy to introduce races that way. On POSIX systems we use advisory locks, which do not prevent the file from being changed or deleted by another process while locked. Consider the following sequence:
Now processes B and C are both updating the
To fix that situation, we would need to always delete the file before unlocking it, and always check the identity of a file after locking it.
That requires a much more intricate locking sequence (B needs to verify the identity of the file it locked), and I'm not entirely sure that it's portable (I don't know whether Windows allows locked files to be removed or renamed).