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

Fix #3697 Improve error handling when tarball fetcher receives bad hash #4240

Merged
merged 7 commits into from
Aug 29, 2017

Conversation

kaylie-alexa
Copy link
Member

Summary
Fix for #3697

  • Previously, the tarball fetcher always piped the content to offline cache path when the request succeeded (<=400), regardless of whether the received hash matched the requested hash or not. So I moved the write process to the finish block of the stream when it checks for the matching hash.
  • Improved warning message to include package name and be more user friendly

Test plan
Added a test case in fetchers

BEFORE
screen shot 2017-08-23 at 8 50 34 am

AFTER

screen shot 2017-08-23 at 8 47 01 am

*note hashes are the same in the screenshots bc I made the code block fail intentionally


if (tarballCachePath) {
validateStream.pipe(fs.createWriteStream(tarballCachePath)).on('error', reject);
}
Copy link
Member

Choose a reason for hiding this comment

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

Won't that cause the tarballs to still be written on the disk even if the validation fails?

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @arcanis. I think what we need is keeping this in the old place and just deleting the file on validation failure before we reject the promise. This would also prevent going over the file two times.

Copy link
Member Author

Choose a reason for hiding this comment

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

yup initial approach was only write when hash matches but realized there are other reasons that would cause failure. updated!

@arcanis arcanis self-assigned this Aug 24, 2017
@BYK
Copy link
Member

BYK commented Aug 25, 2017

LGTM but last word is yours @arcanis

const tarballCachePath = this.getTarballCachePath();

if (tarballMirrorPath && (await fsUtil.exists(tarballMirrorPath))) {
await fsUtil.unlink(tarballMirrorPath);
Copy link
Member Author

Choose a reason for hiding this comment

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

@arcanis just curious, why does the unlinking have to be synchronous here?

Copy link
Member

Choose a reason for hiding this comment

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

One benefit I see is that uncaught exceptions will be logged to the console, and will possibly abort the execution in future Node versions. Apart from that, it shouldn't really matter, but if you do it I suggest you also add a comment to explain it's made on purpose, since it can also be seen as a typo.

@arcanis arcanis merged commit b4c3516 into yarnpkg:master Aug 29, 2017
joaolucasl pushed a commit to joaolucasl/yarn that referenced this pull request Oct 27, 2017
… bad hash (yarnpkg#4240)

* test

* alter commit message

* update snapshot

* review feedback

* move to unlink files in all failed blocks

* lint

* Update tarball-fetcher.js
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.

3 participants