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

Feature Request: Provide an API to react on a stale lock that is reclaimed #105

Open
albe opened this issue May 16, 2021 · 2 comments · May be fixed by #106
Open

Feature Request: Provide an API to react on a stale lock that is reclaimed #105

albe opened this issue May 16, 2021 · 2 comments · May be fixed by #106

Comments

@albe
Copy link

albe commented May 16, 2021

The use case is a storage system (database) that uses a stale lockfile to detect crashes and then execute data recovery procedures (see albe/node-event-storage#165).

Right now, it's not possible to distinguish a lock() call that just created the lock newly from a call that reclaimed a stale lock.
The API method would need to be invoked after the new lock is claimed to prevent the recovery procedure from running twice.
This could be achieved by wrapping the callback into a method that will invoke a special onReclaimed callback similar to onCompromised at https://github.com/moxystudio/node-proper-lockfile/blob/master/lib/lockfile.js#L78

Note that this is a different case than onCompromised, as that only detects locks that can no longer be updated.

Right now to handle this scenario, the calling side needs to track the successful releasing in a separate "marker" file that gets deleted after the lock has been released. This is suboptimal though, because it introduces much more complexity and suffers from a slight inconsistency, if the process fails between releasing the lock and deleting the "marker" file.

Happy to discuss if this is a viable feature or something that unintentionally bloats the API surface of this library.

@satazor
Copy link
Contributor

satazor commented May 16, 2021

Understood the feature request. It would make more sense for the lock method to return the release function as well as how the lock was obtained (standard, reclaimed). However, that would be a breaking change.

While a little bit strange, the onReclaimed seems like the way to go. If you could think about another name for onReclaimed that would include stale, the better (onStaleReclaimed sounds a bit strange, any other suggestion?).

Are you willing to implement a PR with this new feature, docs and tests?

@albe
Copy link
Author

albe commented May 18, 2021

I can take an attempt maybe over the weekend. Thanks for confirming my potential solution!

albe added a commit to albe/node-proper-lockfile that referenced this issue May 28, 2021
@albe albe linked a pull request May 28, 2021 that will close this issue
2 tasks
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

Successfully merging a pull request may close this issue.

2 participants