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: Always close the reporter before exiting #4283

Merged
merged 3 commits into from
Sep 4, 2017

Conversation

arcanis
Copy link
Member

@arcanis arcanis commented Aug 29, 2017

Summary

Fix #4276

In some particular cases, the reporters are not correctly closed before Yarn exits. It makes the process hang, because the reporters are expected to periodically check for the RAM usage. This patch does two things:

  • First the setInterval loop itself is unref, so that it will never prevent the process from exiting.
  • More importantly, the reporter is now correctly closed when exiting in the two cases I've noticed.

Test plan

I don't think tests are required for this fix, since the reproduction steps are fairly narrow (the bug only occurred when using Yarn in an invalid way) and won't allow us to catch any other bug than this one.

Copy link
Contributor

@cpojer cpojer left a comment

Choose a reason for hiding this comment

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

Looks good to me, although the linter has a problem with your call to unref.

I don't want to block this without a test, but if it's easy to add a unit test or something, that would be preferable.

Copy link
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

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

LGTM as well as long as the builds pass.

Do you think we can add a smoke test for this?

@arcanis
Copy link
Member Author

arcanis commented Aug 29, 2017

Hm Flow seems to recognize setInterval as returning a number, which is true for browsers but not for Node. I'll add a $FlowFixMe.

Re: tests, if you think it's better I'll add one.

@BYK
Copy link
Member

BYK commented Aug 30, 2017

If it is not too much trouble, a test would be great. If not, well... 🤷‍♂️

@BYK BYK self-assigned this Sep 4, 2017
Copy link
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

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

Still LGTM but I think AppVeyor failures are legit and need to be fixed before merging.

@@ -152,6 +152,8 @@ export default class BaseReporter {
this.peakMemoryInterval = setInterval(() => {
this.checkPeakMemory();
}, 1000);
// $FlowFixMe: Node's setInterval returns a Timeout, not a Number
this.peakMemoryInterval.unref();
Copy link
Member

Choose a reason for hiding this comment

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

I'm 👍 with this change but curious why clearInterval(this.peakMemoryInterval); in close() below isn't enough.

src/cli/index.js Outdated
@@ -349,10 +349,10 @@ export function main({
return errorReportLoc;
}

const exit = exitCode => {
function exit(exitCode) {
Copy link
Member

Choose a reason for hiding this comment

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

Why convert to "normal" functions from arrow functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because otherwise exit is undefined at lines 178 & 195, since the assignment hasn't been executed yet.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, let's move this above then? Or add a comment if moving up is not possible?

@arcanis arcanis merged commit 593e243 into yarnpkg:master Sep 4, 2017
@yacinehmito
Copy link

I don't think it fixes #4276, although this is a welcome PR.
The problem with the process hanging was just mentioned in passing. The real issue is that yarn remove in a workspace doesn't work.

BYK pushed a commit that referenced this pull request Sep 13, 2017
**Summary**

A combination of changes have caused `yarn upgrade-interactive` to exit with a promise rejection. 

In short, I believe it has always been a problem, but #3995 exposed it to the prompt. 

The child rejection inside of [upgrade-interactive](https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/upgrade-interactive.js#L152) is fine, as it was handled by the `Promise.race` condition; however, rejecting at the parent level inside of [console-reporter](https://github.com/yarnpkg/yarn/blob/master/src/reporters/console/console-reporter.js#L458) causes[ loud-rejection](https://github.com/sindresorhus/loud-rejection) to handle this.

I believe @arcanis 's PR #4283 is what would allow us not to hook into `SIGINT` inside of the console reporter and allow the reporter to cleanly close itself.

**Test Plan**

Will work on some scenarios! This PR needs some more verification on my end ... @BYK @torifat @arcanis please jump in and provide any feedback you think could be helpful! Opened early for visibility :)
joaolucasl pushed a commit to joaolucasl/yarn that referenced this pull request Oct 27, 2017
* Prevents the memory controls from hanging the process

* Update base-reporter.js

* Adds a test
joaolucasl pushed a commit to joaolucasl/yarn that referenced this pull request Oct 27, 2017
**Summary**

A combination of changes have caused `yarn upgrade-interactive` to exit with a promise rejection. 

In short, I believe it has always been a problem, but yarnpkg#3995 exposed it to the prompt. 

The child rejection inside of [upgrade-interactive](https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/upgrade-interactive.js#L152) is fine, as it was handled by the `Promise.race` condition; however, rejecting at the parent level inside of [console-reporter](https://github.com/yarnpkg/yarn/blob/master/src/reporters/console/console-reporter.js#L458) causes[ loud-rejection](https://github.com/sindresorhus/loud-rejection) to handle this.

I believe @arcanis 's PR yarnpkg#4283 is what would allow us not to hook into `SIGINT` inside of the console reporter and allow the reporter to cleanly close itself.

**Test Plan**

Will work on some scenarios! This PR needs some more verification on my end ... @BYK @torifat @arcanis please jump in and provide any feedback you think could be helpful! Opened early for visibility :)
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.

Cannot remove dependency from workspace with yarn
4 participants