Skip to content
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

feat: make staleness check more robust #74

Merged
merged 7 commits into from
Mar 12, 2019

Conversation

hugomrdias
Copy link
Contributor

now we keep track of the mtime updated by the current process, and if we lose some cycles in the update process but recover and the mtime is still ours we do not mark the lock as compromised

closes #71

ref:
ipfs/js-ipfs-repo#188 (comment)

now we keep track of the mtime updated by the current process, and if we lose some cycles in the update process but recover and the mtime is still ours we do not mark the lock as compromised
Copy link
Contributor

@satazor satazor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work @hugomrdias, just some minor changes.

lib/lockfile.js Outdated
// Check if mtime is still ours
options.fs.stat(getLockFile(file, options), (err, stat) => {
// Check mtime ownership
const isMtimeOurs = options.checkMtimeOwnership && lock.stat.mtimeMs === (stat ? stat.mtimeMs : null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not make this an option and just be enabled by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just for testing and it is enabled by default

lib/lockfile.js Outdated Show resolved Hide resolved
lib/lockfile.js Outdated Show resolved Hide resolved
@satazor
Copy link
Contributor

satazor commented Mar 7, 2019

@hugomrdias CI is failing for some reason, can you also check that?

@codecov
Copy link

codecov bot commented Mar 7, 2019

Codecov Report

Merging #74 into master will decrease coverage by 1.78%.
The diff coverage is 95.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #74      +/-   ##
==========================================
- Coverage     100%   98.21%   -1.79%     
==========================================
  Files           4        4              
  Lines         161      168       +7     
  Branches       39       41       +2     
==========================================
+ Hits          161      165       +4     
- Misses          0        3       +3
Impacted Files Coverage Δ
lib/lockfile.js 97.36% <95.45%> (-2.64%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8432bc...7ab8b4a. Read the comment docs.

lib/lockfile.js Outdated Show resolved Hide resolved
lib/lockfile.js Outdated Show resolved Hide resolved
lib/lockfile.js Outdated Show resolved Hide resolved
@satazor
Copy link
Contributor

satazor commented Mar 8, 2019

Feel free to merge! Don’t forget to add the (possible) breaking change in the commit message.

@satazor
Copy link
Contributor

satazor commented Mar 11, 2019

@hugomrdias do you mind doing git pull && npm install? I've resolved a conflict against master that might need the package-lock.json to be updated.

Copy link

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM, I'm going to try this in js-ipfs now and will comment here when done.

lib/lockfile.js Outdated
// which we consider a valid case
// Check if mtime is still ours if it is we can still recover from a system sleep or a busy event loop
options.fs.stat(getLockFile(file, options), (err, stat) => {
const isMtimeOurs = lock.mtime.getTime() === (stat ? stat.mtime.getTime() : null);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: personally I'd move this after the error handling block so you don't need to use a ternary 😄

lib/lockfile.js Outdated
return setLockAsCompromised(file, lock, Object.assign(err, { code: 'ECOMPROMISED' }));
}

lock.updateError = err;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are assigned to but never used...

@alanshaw
Copy link

Ok this is working great for me! 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't use proper-lockfile while debugging memory leaks
3 participants