Skip to content

Fix process.stdout exiting before done - #45

Merged
davidcheung merged 1 commit into
masterfrom
fix-node6-exit2soon
Aug 8, 2016
Merged

davidcheung merged 1 commit into
masterfrom
fix-node6-exit2soon

Conversation

@davidcheung

@davidcheung davidcheung commented Jul 15, 2016 •

Copy link
Copy Markdown
Contributor

In Node v6 process.nextTick exit causes long messages from stdout.write
to exit before the data is finished writing, looks like only happens in child_process.

@bajtos PTAL
cc/ @0candy

Comment thread test/fixtures/app.js
app.dataSource('db', { connector: 'memory' });
var User = loopback.createModel('User');
app.model(User, { dataSource: 'db' });

@davidcheung davidcheung Jul 15, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had to add something to the app template so my stdout buffer is long enough to have this error, open to suggestions of alternative ways to achieve this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is fine. Can you please add a comment explaining that this is needed in order to have the script long enough to trigger output truncation?

@davidcheung

Copy link
Copy Markdown
Contributor Author

Hi @sam-github, would you know if theres any implication on strong-agent if i do
process.stdout.once('drain') instead of process.nextTick

Comment thread bin/lb-ng Outdated
process.nextTick(function() {
// previously used process.nextTick, but in Node 6 is causing
// exit to happen before finish writing leading to missing data
process.stdout.once('drain', function() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about stderr?

https://nodejs.org/docs/latest-v0.12.x/api/all.html#all_process_exitcode is better to use, but not if you need 0.10 support

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • We need to support 0.10
  • We also need to force the process to exit. The reason for that is that some LoopBack connectors open a connection pool at start, and this pool blocks the app from exiting "naturally".

what about stderr?

Good point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sam-github what about i revert to use nextTIck then add process.stdout._handle.setBlocking(true);?
maybe a more direct way to solve the problem to make sure behavior is the same

nodejs/node#6456

Comment thread bin/lb-ng Outdated
function runGenerator() {
// setting stdout to blocking so process.nextTick does not get interupted
// while stdout.write isn't finished in child_process on node v6
process.stdout._handle.setBlocking(true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

doesn't work on 0.10 and 0.12, is that OK? As long as you make sure it only occurs for the generator and doesn't effect any other sub-commands, fine by me.

@davidcheung

Copy link
Copy Markdown
Contributor Author

@slnode test please

1 similar comment
@davidcheung

Copy link
Copy Markdown
Contributor Author

@slnode test please

@davidcheung
davidcheung force-pushed the fix-node6-exit2soon branch from fab4bdb to 8374967 Compare August 5, 2016 16:00
@davidcheung

Copy link
Copy Markdown
Contributor Author

@bajtos PTAL

cc/ @sam-github

Comment thread bin/lb-ng.js Outdated
function waitForEvent(obj, name) {
return new Promise(function(resolve, reject) {
obj.on(name, resolve);
obj.on('error', reject);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think .once is more appropriate both here and on the previous line too.

@bajtos

bajtos commented Aug 8, 2016 •

Copy link
Copy Markdown
Member

One nit-pick, the rest LGTM.

No more reviews are necessary as far I am concerned.

In Node v6 process.nextTick exit causes long messages from stdout.write
to exit before the data is finished writing
@davidcheung
davidcheung force-pushed the fix-node6-exit2soon branch from 8374967 to 6a8c379 Compare August 8, 2016 15:24
@davidcheung

Copy link
Copy Markdown
Contributor Author

@slnode test please

@davidcheung
davidcheung merged commit 6ffc51c into master Aug 8, 2016
@davidcheung
davidcheung deleted the fix-node6-exit2soon branch August 8, 2016 18:38
@bajtos bajtos mentioned this pull request Jun 7, 2017
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