node-proper-lockfile icon indicating copy to clipboard operation
node-proper-lockfile copied to clipboard

feat: add callback option when stale lock is reclaimed

Open albe opened this issue 4 years ago • 1 comments

Closes #105

TODO:

  • [ ] Add tests
  • [ ] Add docs

albe avatar May 28 '21 14:05 albe

One thing I'm not sure about is the race condition for the reclaiming now - if two processes start with a stale lock, then one starts to delete it, the other in the meantime acquires the lock and the second one then fails to acquire the lock, the callback will not be invoked and the information that a stale lock existed is lost. If however the callback is invoked immediately after removing the stale lock, then multiple processes could invoke the onReclaimedStale (or whatever it will be called finally) callback, which is potentially unintended. So can we make the "reclaiming" atomic? i.e. instead of "delete + acquire" just overwrite the existing lock?

albe avatar May 28 '21 15:05 albe