From 57b884a9d5f6920fad6e9288f774124a197f2d53 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 21 Nov 2018 16:45:22 +0000 Subject: [PATCH 1/2] fix: fix staleness check --- src/lock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lock.js b/src/lock.js index 9f14a66d..2000ec05 100644 --- a/src/lock.js +++ b/src/lock.js @@ -19,7 +19,7 @@ exports.lock = (dir, callback) => { const file = path.join(dir, lockFile) log('locking %s', file) - lock(dir, {lockfilePath: file}) + lock(dir, {lockfilePath: file, stale: 20000}) .then(release => { callback(null, {close: (cb) => { release() From 0c510cada9ba3fc0c9c41ca6c3468896e833146e Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Tue, 27 Nov 2018 16:08:48 +0000 Subject: [PATCH 2/2] fix: extract stale value to const --- src/lock.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lock.js b/src/lock.js index 2000ec05..38c932ba 100644 --- a/src/lock.js +++ b/src/lock.js @@ -5,9 +5,19 @@ const debug = require('debug') const { lock } = require('proper-lockfile') const log = debug('repo:lock') - const lockFile = 'repo.lock' +/** + * Duration in milliseconds in which the lock is considered stale + * @see https://github.com/moxystudio/node-proper-lockfile#lockfile-options + * The default value of 10000 was too low for ipfs and sometimes `proper-lockfile` + * would throw an exception because it couldn't update the lock file mtime within + * the 10s threshold. @see https://github.com/ipfs/js-ipfs-repo/pull/182 + * Increasing to 20s is a temporary fix a permanent fix should be implemented in + * the future. + */ +const STALE_TIME = 20000 + /** * Lock the repo in the given dir. * @@ -19,7 +29,7 @@ exports.lock = (dir, callback) => { const file = path.join(dir, lockFile) log('locking %s', file) - lock(dir, {lockfilePath: file, stale: 20000}) + lock(dir, {lockfilePath: file, stale: STALE_TIME}) .then(release => { callback(null, {close: (cb) => { release()