Skip to content
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

Delete released lock files on unix #27

Closed
spokorski opened this issue Dec 22, 2017 · 4 comments
Closed

Delete released lock files on unix #27

spokorski opened this issue Dec 22, 2017 · 4 comments

Comments

@spokorski
Copy link
Contributor

spokorski commented Dec 22, 2017

After they are released, an attempt is made to delete the lock files in both the WindowsFileLock and SoftFileLock classes, but not in UnixFileLock. Is there a reason this is missing from UnixFileLock? It seems strange that lock files clean up after themselves on some systems but not on others.

@AdorablePotato
Copy link
Contributor

Ups, there's no reason for that, I simply forgot to clean up.
Thank you for the patch!

@RPiAwesomeness
Copy link

RPiAwesomeness commented May 31, 2018

I'm not sure if I'm doing this incorrectly but it appears that this is happening again on Ubuntu for version 3.0.4. I can see the debug messages coming through and it seems to be acquiring, locking, and releasing correctly, but there are a bunch of .lock files still laying around.

Currently I'm using the following:

lock_path = out_path + ".lock"
lock = FileLock(lock_path)

try:
    with lock.acquire(timeout=10):
        ...
except Timeout as e:
    ....

Looking at the source it appears that you removed this functionality again?
https://filelock.readthedocs.io/en/latest/_modules/filelock.html#UnixFileLock

@int-ua
Copy link

int-ua commented Jun 26, 2019

3.0.12 affected. Please reopen. SoftFileLock works as expected.

@charles-dyfis-net
Copy link

charles-dyfis-net commented Sep 27, 2019

This feature request is extremely harmful.

Deleting lockfiles on UNIX causes a race condition. Consider the following set of events:

  • Program A creates and opens (as an atomic operation) a file A.lck.
  • Program A grabs a lock on the file handle it holds on that file; this operation succeeds.
  • Program B opens A.lck.
  • Program B requests a lock on the file handle; this operation blocks.
  • Program A deletes A.lck.
  • Program A closes its file handle, which makes program B able to get a lock on the file handle it already holds, on the now-deleted copy of A.lck.
  • Program C creates and opens (as an atomic operation) a new file under the name A.lck.
  • Program C grabs a lock on the file handle it holds on this file; because they're two different files (even if under the same name), this succeeds.

...thus, you have both programs B and C thinking they hold the same lock.


On Windows this can't happen, because directory entries can't be deleted until no handles on the files that back them exist. That's untrue on UNIX; thus, different behavior is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants