Git Product home page Git Product logo

node-proper-lockfile's Introduction

proper-lockfile

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status

An inter-process and inter-machine lockfile utility that works on a local or network file system.

Installation

$ npm install proper-lockfile

Design

There are various ways to achieve file locking.

This library utilizes the mkdir strategy which works atomically on any kind of file system, even network based ones. The lockfile path is based on the file path you are trying to lock by suffixing it with .lock.

When a lock is successfully acquired, the lockfile's mtime (modified time) is periodically updated to prevent staleness. This allows to effectively check if a lock is stale by checking its mtime against a stale threshold. If the update of the mtime fails several times, the lock might be compromised. The mtime is supported in almost every filesystem.

Comparison

This library is similar to lockfile but the latter has some drawbacks:

  • It relies on open with O_EXCL flag which has problems in network file systems. proper-lockfile uses mkdir which doesn't have this issue.

O_EXCL is broken on NFS file systems; programs which rely on it for performing locking tasks will contain a race condition.

  • The lockfile staleness check is done via ctime (creation time) which is unsuitable for long running processes. proper-lockfile constantly updates lockfiles mtime to do proper staleness check.

  • It does not check if the lockfile was compromised which can lead to undesirable situations. proper-lockfile checks the lockfile when updating the mtime.

  • It has a default value of 0 for the stale option which isn't good because any crash or process kill that the package can't handle gracefully will leave the lock active forever.

Compromised

proper-lockfile does not detect cases in which:

  • A lockfile is manually removed and someone else acquires the lock right after
  • Different stale/update values are being used for the same file, possibly causing two locks to be acquired on the same file

proper-lockfile detects cases in which:

  • Updates to the lockfile fail
  • Updates take longer than expected, possibly causing the lock to become stale for a certain amount of time

As you see, the first two are a consequence of bad usage. Technically, it was possible to detect the first two but it would introduce complexity and eventual race conditions.

Usage

.lock(file, [options])

Tries to acquire a lock on file or rejects the promise on error.

If the lock succeeds, a release function is provided that should be called when you want to release the lock. The release function also rejects the promise on error (e.g. when the lock was already compromised).

Available options:

  • stale: Duration in milliseconds in which the lock is considered stale, defaults to 10000 (minimum value is 5000)
  • update: The interval in milliseconds in which the lockfile's mtime will be updated, defaults to stale/2 (minimum value is 1000, maximum value is stale/2)
  • retries: The number of retries or a retry options object, defaults to 0
  • realpath: Resolve symlinks using realpath, defaults to true (note that if true, the file must exist previously)
  • fs: A custom fs to use, defaults to graceful-fs
  • onCompromised: Called if the lock gets compromised, defaults to a function that simply throws the error which will probably cause the process to die
  • lockfilePath: Custom lockfile path. e.g.: If you want to lock a directory and create the lock file inside it, you can pass file as <dir path> and options.lockfilePath as <dir path>/dir.lock
const lockfile = require('proper-lockfile');

lockfile.lock('some/file')
.then((release) => {
    // Do something while the file is locked

    // Call the provided release function when you're done,
    // which will also return a promise
    return release();
})
.catch((e) => {
    // either lock could not be acquired
    // or releasing it failed
    console.error(e)
});

// Alternatively, you may use lockfile('some/file') directly.

.unlock(file, [options])

Releases a previously acquired lock on file or rejects the promise on error.

Whenever possible you should use the release function instead (as exemplified above). Still there are cases in which it's hard to keep a reference to it around code. In those cases unlock() might be handy.

Available options:

  • realpath: Resolve symlinks using realpath, defaults to true (note that if true, the file must exist previously)
  • fs: A custom fs to use, defaults to graceful-fs
  • lockfilePath: Custom lockfile path. e.g.: If you want to lock a directory and create the lock file inside it, you can pass file as <dir path> and options.lockfilePath as <dir path>/dir.lock
const lockfile = require('proper-lockfile');

lockfile.lock('some/file')
.then(() => {
    // Do something while the file is locked

    // Later..
    return lockfile.unlock('some/file');
});

.check(file, [options])

Check if the file is locked and its lockfile is not stale, rejects the promise on error.

Available options:

  • stale: Duration in milliseconds in which the lock is considered stale, defaults to 10000 (minimum value is 5000)
  • realpath: Resolve symlinks using realpath, defaults to true (note that if true, the file must exist previously)
  • fs: A custom fs to use, defaults to graceful-fs
  • lockfilePath: Custom lockfile path. e.g.: If you want to lock a directory and create the lock file inside it, you can pass file as <dir path> and options.lockfilePath as <dir path>/dir.lock
const lockfile = require('proper-lockfile');

lockfile.check('some/file')
.then((isLocked) => {
    // isLocked will be true if 'some/file' is locked, false otherwise
});

.lockSync(file, [options])

Sync version of .lock().
Returns the release function or throws on error.

.unlockSync(file, [options])

Sync version of .unlock().
Throws on error.

.checkSync(file, [options])

Sync version of .check(). Returns a boolean or throws on error.

Graceful exit

proper-lockfile automatically removes locks if the process exits, except if the process is killed with SIGKILL or it crashes due to a VM fatal error (e.g.: out of memory).

Tests

$ npm test
$ npm test -- --watch during development

The test suite is very extensive. There's even a stress test to guarantee exclusiveness of locks.

License

Released under the MIT License.

node-proper-lockfile's People

Contributors

alanshaw avatar bmeck avatar coreybutler avatar dependabot[bot] avatar elratondefuego avatar greenkeeper[bot] avatar greenkeeperio-bot avatar hugomrdias avatar lucianbuzzo avatar marcooliveira avatar martonw avatar pimlie avatar satazor avatar timbowhite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-proper-lockfile's Issues

Error: Lock file is already being held

I'm using proper-lockfile in a Jest test suite which is executed in parallel across multiple processes.

My code

    import * as lockFile from 'proper-lockfile';
    import {readJsonSync, writeJSONSync} from "fs-extra";
    const startPort = 28000;
    const portFile = '/tmp/glut-integration-port.txt';

>   lockFile.lockSync(portFile, {stale: 30000});
    let port = startPort;
    try {
        port = readJsonSync(portFile, {throws: false}) || startPort;
        if (port > 50000) {
            port = startPort;
        }
        const thisPort = port + 1;
        writeJSONSync(portFile, thisPort);
    } finally {
        lockFile.unlockSync(portFile);
    }

When Jest is executed I get randomly the following error:

Error: Lock file is already being held

    at /Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/lockfile.js:68:47
    at Object.newFs.<computed> [as stat] (/Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/adapter.js:20:13)
    at /Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/lockfile.js:56:20
    at Object.newFs.<computed> [as mkdir] (/Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/adapter.js:17:24)
    at acquireLock (/Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/lockfile.js:29:16)
    at RetryOperation._fn (/Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/lockfile.js:233:13)
    at RetryOperation.Object.<anonymous>.RetryOperation.attempt (/Users/marc/bude/glut.ts/node_modules/proper-lockfile/node_modules/retry/lib/retry_operation.js:112:8)
    at /Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/lockfile.js:232:19
    at Object.newFs.<computed> [as realpath] (/Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/adapter.js:20:13)
    at resolveCanonicalPath (/Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/lockfile.js:22:16)
    at lock (/Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/lockfile.js:224:5)
    at /Users/marc/bude/glut.ts/node_modules/proper-lockfile/lib/adapter.js:53:9
    at AsyncFunction.lockSync (/Users/marc/bude/glut.ts/node_modules/proper-lockfile/index.js:13:42)

Environment:

  npm: '6.9.0',
  node: '12.2.0',
  macOS 10.15.1

The lib doesn't work as expected, or I don't understand it's purpose

OS: Windows 10
Node.js version: 16.14.2

`const lockfile = require('proper-lockfile');
const fs = require('fs');

     lockfile.lock('./file.txt')

     .then((release)=>{             
         fs.writeFileSync('./file.txt', 'some text');
         return release();
     })    
     .catch((e) => {
        console.error(e)
    }); 

`

I expected that the file.txt will NOT be written, but it actually is. If the code doesn't protect the file from be written, what is the purpose of the library? Thanks!

Cannot read property 'updateTimeout' of undefined

I got following error, when I close an electron app window, and click the tray icon to restart that app.

Uncaught Exception:
TypeError: Cannot read property 'updateTimeout' of undefined
    at updateLock (/xxx/SoLiDBox.app/Contents/Resources/app.asar/node_modules/proper-lockfile/lib/lockfile.js:90:14)
    at /xxx/SoLiDBox.app/Contents/Resources/app.asar/node_modules/proper-lockfile/lib/lockfile.js:136:13
    at FSReqCallback.oncomplete (fs.js:153:23)

Uncaught Exception

proper-lockfile/index.js:86
lock.updateDelay = lock.updateDelay || options.update;
^
TypeError: Cannot read property 'updateDelay' of undefined
at updateLock (proper-lockfile/index.js:86:28)
at proper-lockfile/index.js:119:13
at Object.oncomplete (evalmachine.:107:15)

Not sure what causes the error, but I'd prefer an err object vs an exception

Cannot kill debug client

When this package is used, we can't exit node --inspect[-*] debug server with ctrl-C, or kill it with SIGTERM. This is due to tapjs/signal-exit#71.

1$ # terminal 1: debug server
1$ cat index.js  # very simple script
console.log("a");

1$ node --inspect-brk index.js

2$ # terminal 2: debug client
2$ node inspect --port=9229
connecting to 127.0.0.1:9229 ... ok
Break on start in index.js:1
> 1 console.log("a");
  2 
debug> 

# terminal1
Debugger attached.
^C
1$ # killed with Ctrl-C

When proper-lockfile is used:

1$ cat index.js
const lockfile = require("proper-lockfile");
console.log("a");

1$ node --inspect-brk index.js

2$ node inspect --port=9229
connecting to 127.0.0.1:9229 ... ok
Break on start in index.js:1
> 1 const lockfile = require("proper-lockfile");
  2 console.log("a");
  3 
debug> n
break in index.js:2
  1 const lockfile = require("proper-lockfile");
> 2 console.log("a");
  3 

# now we can't kill the server!

# terminal1
Debugger attached.
^C^C^C^C^C

Tested environment:

  • Ubuntu 20.04 amd64
  • Linux kernel 5.15.39+
  • Node.js v16.18.1

Pass recursive option during mkdir

Hello I had an error while using you library.

Error: ENOENT: no such file or directory, lstat '/Users/me/folder/file.js' occured while running the following code from /Users/me/ with /Users/me/folder not created.

const lockFile = require("proper-lockfile")

lockFile.lock(`${__dirname}/folder/file.js`)

I guess you could pass {recursive: true} to mkdir here :

options.fs.mkdir(getLockFile(file, options), (err) => {

The recursive option is a recent addition to nodejs api: https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback.

What do you think ?

bug: Ctrl-C doesn't work if just requiring proper-lockfile

Consider the following snippet:

const properLockfile = require('proper-lockfile'); // 1

for (let i = 0; i < 1_000_000; i += 1)
  console.log(i);

It take a few seconds to run the snippet. Unfortunately, hitting Ctrl-C to abort execution does not work.
However, when removing the (1) line with proper-lockfile require, Ctrl-C would work as expected.

This has been reported to us downstream at Playwright: microsoft/playwright#19418

macOS: Error: ENOENT: no such file or directory, lstat '/private/tmp/ ...

Based on the readme:

realpath: Resolve symlinks using realpath, defaults to true (note that if true, the file must exist previously)

This explains that the setting is true by default, and because /tmp is symlinked to /private/tmp on macOS, it produces this ENOENT problem whenever we try to use a lockfile in /tmp.

What is the official workaround for this? Disabling realpath works for me in testing. But I am unclear on what are the drawbacks of specifying realpath: false and why exactly this fails. Is realpath intended as a security measure or a convenience measure that has lower security?

I was beginning to think that manually creating the lockfile is what I'm supposed to do, but on second thought that seems to go against the notion of the lockfile itself...

Possibility to pass the lock to another process

My use case: I want to acquire a lock on a directory and, if successful, run a new process which will do some work in this directory and release the lock at the end.

Is unlock(path) the way to achieve this or is the lock linked to the current process?

An in-range update of mocha is breaking the build 🚨

Version 3.5.0 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.4.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes free-as-in-freezing

3.5.0 / 2017-07-31

πŸ“° News

  • Mocha now has a code of conduct (thanks @kungapal!).
  • Old issues and PRs are now being marked "stale" by Probot's "Stale" plugin. If an issue is marked as such, and you would like to see it remain open, simply add a new comment to the ticket or PR.
  • WARNING: Support for non-ES5-compliant environments will be dropped starting with version 4.0.0 of Mocha!

πŸ”’ Security Fixes

πŸŽ‰ Enhancements

  • #2696: Add --forbid-only and --forbid-pending flags. Use these in CI or hooks to ensure tests aren't accidentally being skipped! (@charlierudolph)
  • #2813: Support Node.js 8's --napi-modules flag (@jupp0r)

πŸ”© Other

Commits

The new version differs by 34 commits.

  • 82d879f Release v3.5.0
  • bf687ce update mocha.js for v3.5.0
  • ec73c9a update date for release of v3.5.0 in CHANGELOG [ci skip]
  • 1ba2cfc update CHANGELOG.md for v3.5.0 [ci skip]
  • 065e14e remove custom install script from travis (no longer needed)
  • 4e87046 update karma-sauce-launcher URL for npm@5
  • 6886ccc increase timeout for slow-grepping test
  • 2408d90 Make dependencies use older version of readable-stream to work around incompatibilities introduced by 2.3.0 on June 19th
  • 68a1466 Try not clearing the env for debug in the integration test and see if that fixes Node 0.10 on AppVeyor; if need be, some other fix/workaround can be applied to handle whatever was up with debug without causing this issue
  • 958fbb4 Update new tests to work in browser per test hierarchy reorganization
  • 1df7c94 Merge pull request #2704 from seppevs/increase_test_coverage_of_mocha_js
  • 1f270cd Stop timing out (#2889)
  • 27c7496 upgrade to [email protected]; closes #2859 (#2860)
  • 50fc47d fix CI; closes #2867 (#2868)
  • 1b1377c Add test for ignoreLeaks and fix descriptions

There are 34 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Impossible to compose a lock..

when attempting to compose a release function, e.g. so that re-requesting the lock (if it exists) returns the release function, it fails stating:

TypeError: method is not a function

Example implementation:

        const release = getLock(file);
        let released = false;
        locks[file] = () => {
            if (!released) {
                released = true;
                release();
                delete locks[file];
            }
        };

Suspected cause: you're using function composition so that even with an arrow function, somehow scope is lost and method returns as undefined

lock file prior to existence

right now you cannot lock() a file unless it is already on disk, this makes it hard to guarantee that files can be locked while their content is still being generated but the filename needs to be reserved

(docs) missing information about throwing errors

Now that it understand everything it might be logical, but the README doesnt really mention that lock() or the release() returned by lock throws errors. Was looking at the source and it took longer than I want to admit to realize that the callback called in unlock is ofc not visible anywhere when you use async/await syntax (but still used very much so).

A little note about this in the readme would be helpful :)

An in-range update of mocha is breaking the build 🚨

Version 3.4.1 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.4.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes Ohai CRLF...

Fixed a publishing mishap with git's autocrlf settings.

Commits

The new version differs by 3 commits0.

false

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of rimraf is breaking the build 🚨

Version 2.6.1 of rimraf just got published.

Branch Build failing 🚨
Dependency rimraf
Current Version 2.6.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As rimraf is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Commits

The new version differs by 2 commits .

  • d84fe2c v2.6.1
  • e8cd685 only run rmdirSync 'retries' times when it throws

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Electron start with an error alert relate this package.

I am using electron with ipfs. When start running ipfs, after 20 seconds, it pop up an error alert.

Uncaught Exception:
Error: Unable to update lock within the stale threshold
    at options.fs.stat (/Users/yinjames/Projects/lc-ipfs/node_modules/proper-lockfile/lib/lockfile.js:121:25)
    at /Users/yinjames/Projects/lc-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:155:5)

It seems like an error with node-proper-lockfile. So I post an issue here. You can reproduce this error by using ipfs electron example.
Relate post here: ipfs/js-ipfs#1962

Race condition in `mtime-precision/probe`

Two parallel calls, cachedPrecision is not defined in both, both will call utimes then stat, and Object.defineProperty will be called twice.

This does not throw TypeError: Cannot redefine property because the new value to be defined is the existing value.

TypeError unref of undefined when running proper-lockfile inside of react-scripts test

Background

I'm mounting ipfs, which has a dependency on ipfs-repo inside of a react app generated via create-react-app. Running a very basic render test results in the following exception.

Problematic Command

$ NODE_PATH=src/ CI=true react-scripts test && yarn run lint

Exception

/Users/marcusbernales/Workspace/odyssey/node_modules/proper-lockfile/lib/lockfile.js:180
    if (lock.updateTimeout.unref) {
                           ^

TypeError: Cannot read property 'unref' of undefined
    at updateLock (/Users/marcusbernales/Workspace/odyssey/node_modules/proper-lockfile/lib/lockfile.js:180:28)
    at /Users/marcusbernales/Workspace/odyssey/node_modules/proper-lockfile/lib/lockfile.js:252:17
    at /Users/marcusbernales/Workspace/odyssey/node_modules/proper-lockfile/lib/lockfile.js:42:17
    at /Users/marcusbernales/Workspace/odyssey/node_modules/proper-lockfile/lib/mtime-precision.js:39:13
    at callback (/Users/marcusbernales/Workspace/odyssey/node_modules/graceful-fs/polyfills.js:295:20)
    at callback (/Users/marcusbernales/Workspace/odyssey/node_modules/graceful-fs/polyfills.js:295:20)
    at FSReqCallback.oncomplete (fs.js:170:5)

Potential Solution

Modifying lockfile.js:180 to check for the existence of lock.updateTimeout first solves the runtime error. Would love to discuss whether that's the right way to go about it.

compare speed test etc

hey all

I would love to compare the functionality of this lib with my lib
https://github.com/ORESoftware/live-mutex

I haven't tried yours but I will soon. ultimately, I think a distributed lock with failover is ideal for most applications, but I guess there is a small niche for non-distributed networked locks.

Locks taking longer than I expect

Hello! I am trying out this library and I just wanted to check if I am using the library correctly and if this is expected. In the repo below I have a bash script that launches 4 concurrent processes to test out the locking and it is taking up to 7 seconds to acquire the lock even though the file locks are only held for 2-3 milliseconds.

https://github.com/dsellarsnr/lock-problem

getLocks exposes internal details of locked files

Just a suggestion, but getLocks is only used in this project for testing (but maybe other people are using it for other reasons) - consider removing it? Why would you need access to this internal data? It's easily corrupted if people assign to the lock objects and I can't think of a reason why you'd need access to any information other than the paths of the files that are locked (but arguably an application would be keeping track of these anyway).

Should just return a list of file paths that are locked? Or perhaps better - remove it, and have a test helper that keeps track of your locks so it can unlock them all easily.

Cannot read property 'updateTimeout' of undefined

Ocasionally I get this error,

 Uncaught TypeError: Cannot read properties of undefined (reading 'updateTimeout')
    at updateLock (node_modules/proper-lockfile/lib/lockfile.js:104:14)
    at /home/user2/Nextcloud/projects/plebbit/plebbit-js/node_modules/proper-lockfile/lib/lockfile.js:167:17
    at FSReqCallback.oncomplete (node:fs:192:23)
    at FSReqCallback.callbackTrampoline (node:internal/async_hooks:130:17)

Seems like locks[file] is not defined by the time updateLock is called. Would love any insights on why.

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

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.

electron app seems break

hello,

is use a npm module wich use your project and when i try to run my application into electron i have this issue :

/node_modules/proper-lockfile/lib/lockfile.js:47
                    return acquireLock(file, { ...options, stale: 0 }, callback);
                                               ^^^
SyntaxError: Unexpected token ...
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.require.extensions.(anonymous function) [as .js] (/home/josselin/develop/telescope/node_modules/electron-compile/lib/require-hook.js:77:14)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/josselin/develop/telescope/node_modules/proper-lockfile/index.js:3:18)
    at Object.<anonymous> (/home/josselin/develop/telescope/node_modules/proper-lockfile/index.js:42:3)```

any idea ? 

Regards

An in-range update of eslint is breaking the build 🚨

Version 3.12.1 of eslint just got published.

Branch Build failing 🚨
Dependency eslint
Current Version 3.12.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As eslint is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v3.12.1
  • 0ad4d33 Fix: indent regression with function calls (fixes #7732, fixes #7733) (#7734) (Teddy Katz)
  • ab246dd Docs: Rules restricting globals/properties/syntax are linked together (#7743) (Kevin Partington)
  • df2f115 Docs: Add eslint-config-mdcs to JSCS Migration Guide (#7737) (Joshua Koo)
  • 4b77333 Build: avoid creating broken rule links in the changelog (#7731) (Teddy Katz)
Commits

The new version differs by 6 commits .

  • 9679daa 3.12.1
  • 8a31bc8 Build: package.json and changelog update for 3.12.1
  • 0ad4d33 Fix: indent regression with function calls (fixes #7732, fixes #7733) (#7734)
  • ab246dd Docs: Rules restricting globals/properties/syntax are linked together (#7743)
  • df2f115 Docs: Add eslint-config-mdcs to JSCS Migration Guide (#7737)
  • 4b77333 Build: avoid creating broken rule links in the changelog (#7731)

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

[Feature Request] Export a defaultOptions object

If users wish to deviate from the default options, it would be helpful to be able to do, say:

lockfile.defaultOptions.fs = require('fs');

or

lockfile.updateDefaults({ fs: require('fs') });

This would be easily implementable using Object.assign.

Note the second implementation would be to prevent overwriting the lockfile.defaultOptions with an object that is missing options (including in cases where options are added later on), though I'm personally a fan of the first implementation, and this issue can avoided by using something like this in function calls.

var options = Object.assign({}, packageDefaultOptions, userDefaultOptions, invocationOptions);

Follow up on the mtime check precision

PR #78 fixed an issue regarding precision of mtime. The implemented approach was to deal with round issues when checking. A more correct approach was suggested during the review.

This issue is a reminder to follow up on that and implement that approach instead.

Throws error if path leading to a file doesn't exist yet.

First of all: thanks for the great lib!

I've encountered a weird issue.

This works fine even if the file doesn't exist:

lockfile.lock('./file.txt');

This however throws errors, when the path doesn't exist yet:

lockfile.lock('./path/that/does/not/exist/file.txt');

For the time being I've just made sure to use a wrapper that ensures directory paths leading to files that are about to be locked (whether existing or not yet) exist.

compromised lock throws error when release is called

Is it intended behaviour that calling release for a lock which has been compromised throws an error? It feels counter-intuitive to me. Maybe we could add a strict mode, which is default true but when its false a compromised lock doesnt throw an error?

Difference between lock.mtime and stat.mtime precision

Possibly related to #79

We are still getting a lot of reports about stale locks, often on CI platforms (and docker). One possible cause might be users who are using Node <v9. It appears that in Node v9 there can be a difference in precision about the lock.mtime which is set with what stat.mtime reports back:

updateLock 2019-03-23T09:30:18.519Z 2019-03-23T09:30:18.519Z                                                             10:30:33
precision ms                                                                                                             10:30:33
createdMtimeChecked 1553333418519 1553333418519                                                                          10:30:33
mtime set to 2019-03-23T09:30:33.523Z                                                                                    10:30:33
updateLock 2019-03-23T09:30:33.523Z 2019-03-23T09:30:33.000Z                                                             10:30:48
precision ms                                                                                                             10:30:48
createdMtimeChecked 1553333433523 1553333433000           

(lines above are: <function.name> <lock.mtime> <stat.mtime>)

After the last line the lock gets compromised due to the 523ms difference

-- edit --
I removed Node v9 from the title because actually I am not sure if this is really a Node v9 issue only. It might very well be a Node v10+ issue as well which just doesnt show as often / repeatedly due to the general (performance) improvements made in v10+

Can't use proper-lockfile while debugging memory leaks

I'm trying to debug memory leaks which involves generating heap dumps. This tends to peg the CPU - when it's done, the process explodes with:

/path/to/node_modules/proper-lockfile/lib/lockfile.js:181
        onCompromised: (err) => { throw err; },
                                  ^

Error: Unable to update lock within the stale threshold
    at options.fs.utimes (/path/to/node_modules/proper-lockfile/lib/lockfile.js:109:21)
    at FSReqWrap.oncomplete (fs.js:141:20)

Compromised locks

Hi,
can you please explain what "compromised locks" are?
Also, in the README, the lock signature shows that there are two callbacks, compromised and callback but I don't see any example of usage of compromised. Instead, from what I undestand, a single callback is always used (err, release).

Thank you

It doesn't work in Windows, or I don't understand it's logic

I'm able to write to a file despite the library is working. Here is my "locking" code:


const file = './file.txt';

function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

// === main logic ===
lockfile.lock(file)
.then(async (release) => {

    await delay(10000);

    return release();
})
.catch((e) => {
    console.error(e)
});

It locks the file.txt for 10 seconds, and during this time I shouldn't be able to write the file from other processes(if I understand it correctly), but I can open the file in windows "notepad" and change the text.

Here is the code I run in parallel, and it also does rewrite the file.txt :


(() => {
    try {
        const fd = fs.openSync('./file.txt', 'a+');
        fs.writeFileSync(fd, 'some nasty text')
    } catch (e) {
        console.error(e);
    }
})();

So, what does the lib do?
Thanks!

unref lock check interval

I believe that lock files have no need for keeping a node process alive if there is no work being done w/ them. Is there any reason we cannot unref the timer?

An in-range update of lint-staged is breaking the build 🚨

The devDependency lint-staged was updated from 8.1.0 to 8.1.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

lint-staged is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v8.1.1

8.1.1 (2019-01-28)

Bug Fixes

  • Fix configuration validation and allow specifying custom renderers (#572) (d5e738d), closes #567
Commits

The new version differs by 7 commits.

  • d5e738d fix: Fix configuration validation and allow specifying custom renderers (#572)
  • 406a0c0 chore: Revert "chore: pin cosmiconfig to 5.0.6" (#571)
  • adfc1d4 docs(readme): Add example for environment variables (#564)
  • 73e04d7 chore: Use unmock to get rid of mock hoisting (#563)
  • ac8cdf1 docs: Remove comment about hunks support (#553)
  • 352ab8c docs: Update for JetBrains support (#552)
  • 30576d6 chore: Upgrade semantic-release to latest (#548)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.