A robust inter-process and inter-machine lockfile utility for Node.js that works reliably on local and network file systems.
proper-lockfile is a Node.js library that provides reliable file locking for coordinating access to shared resources across multiple processes and machines. It solves the problem of race conditions and resource conflicts in distributed systems by implementing a robust locking mechanism that works consistently on both local and network file systems.
Node.js developers building applications that require coordination between multiple processes or machines accessing shared files, particularly those working with network file systems or distributed architectures.
Developers choose proper-lockfile because it uses the reliable `mkdir` strategy instead of problematic `O_EXCL` flags, provides automatic staleness prevention through mtime updates, detects compromised locks, and works correctly on network file systems where other solutions fail.
An inter-process and inter-machine lockfile utility that works on a local or network file system.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses atomic `mkdir` operations that work correctly on network file systems like NFS, avoiding the broken `O_EXCL` flag issues mentioned in the comparison with other libraries.
Periodically updates lockfile mtime with configurable intervals and stale thresholds, preventing indefinite blocking and ensuring locks don't become orphaned.
Monitors lockfile updates for failures or delays, alerting users via the `onCompromised` callback to handle potential issues proactively.
Offers customizable options like retry strategies, custom filesystem implementations, and lockfile paths, adapting to diverse use cases from local to distributed environments.
Automatically removes locks on normal process termination, reducing cleanup overhead, though it admits limitations with SIGKILL or fatal crashes.
Explicitly cannot detect cases like manual lock removal or inconsistent configuration usage, which the README admits could lead to race conditions in bad usage scenarios.
Relies on filesystem operations for locking, introducing latency compared to in-memory solutions and making it unsuitable for high-performance, low-latency applications.
Requires careful tuning of `stale`, `update`, and `retries` options to avoid issues; misconfiguration can cause ineffective locks or increased resource contention.