filelock icon indicating copy to clipboard operation
filelock copied to clipboard

filelock expiration

Open beasteers opened this issue 4 years ago • 6 comments

To avoid the case where lock files accidentally get left and lock things forever, we could have the process that acquires the lock set an expiration time on the lock. and if it's expired, the other process can assume that the process died or something and delete and re-acquire the lock.

beasteers avatar Apr 23 '20 18:04 beasteers

I guess you can achieve it by yourself. For example, you can write a code: if waiting more than 1 hour, just delete the lock file, and retry to acquire the lock.

Jingnan-Jia avatar Mar 13 '21 22:03 Jingnan-Jia

Hello, if you make a PR for this (with tests) we would be happy to review it, thanks!

gaborbernat avatar Sep 27 '21 08:09 gaborbernat

I am interested in this feature and was wondering how to implement it myself. Is there a recognized method for checking the lock file modification time and then removing it without the danger of race conditions?

rayosborn avatar Feb 16 '22 20:02 rayosborn

Not that I'm aware of, you'd likely have to do the research and then implement it 😂

gaborbernat avatar Feb 16 '22 20:02 gaborbernat

I was afraid of that. So far, I have not been successful in my investigations and I don't have any expertise in Posix filesystem arcana. In fact, it was Googling this topic that led me to your module.

rayosborn avatar Feb 16 '22 21:02 rayosborn

Perhaps a new PIDLock could be defined that saves the pid of the lock. If the lock is held by a pid that no longer exists, the the lock is destroyed. The trick is doing this in a race-condition free manner.

Perhaps this is a starting point? https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition

TheMatt2 avatar Apr 09 '23 03:04 TheMatt2