Skip to content

fix: fix staleness check #182

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

Merged
merged 2 commits into from
Nov 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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