-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stale locks are not removed #1
Comments
Thanks for the report. Since I find file-locking is easy to get wrong, locket intentionally does a minimal amount of work to implement file locks. I'd have to check to see what the correct behaviour is to remove a lock file without introducing race conditions, but I'm afraid I don't have the time right now. If you'd like to investigate yourself, and submit a pull request, then that'd be great! |
I'm not sure this is possible to implement since you I don't know how you'd atomically release the lock and delete the file. But presumably other programs do this successfully, so how do they implement this? Assume that you unlock the file and then delete it. I think there's a possible race condition:
What if we delete the file then unlock it?
Come to think of it, the second race condition happens regardless of whether you unlink then unlock, or unlock then unlink. The problem is really that you want to lock on a path, not a file, but the conversion of a path to a file doesn't happen atomically with the locking. I'm not particularly familiar with the implementation of locking (neither fcntl nor msvcrt), so if anybody knows whether the above is actually true, let me know! |
Thinking a bit more, I suspect delete then unlock works if you stat the path and stat the fd, and make sure they're actually the same inode just after acquiring the fcntl lock. Not certain if this is true on Windows/msvcrt though. |
I think you can use os.open(O_CREAT | O_EXCL) to make sure you do not open |
But presumably using |
Great desc of potential race conditions, @mwilliamson |
Lock file should be removed after lock is released. But it is not.
The text was updated successfully, but these errors were encountered: