Skip to content

Commit

Permalink
fix: fix staleness check (#182)
Browse files Browse the repository at this point in the history
* fix: fix staleness check

* fix: extract stale value to const
  • Loading branch information
hugomrdias authored and jacobheun committed Nov 28, 2018
1 parent 9041f4a commit ede5dd6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -19,7 +29,7 @@ exports.lock = (dir, callback) => {
const file = path.join(dir, lockFile)
log('locking %s', file)

lock(dir, {lockfilePath: file})
lock(dir, {lockfilePath: file, stale: STALE_TIME})
.then(release => {
callback(null, {close: (cb) => {
release()
Expand Down

0 comments on commit ede5dd6

Please sign in to comment.