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 child process stdio data loss with slow piped consumers #7185

Conversation

petrosagg
Copy link

Checklist
  • tests and code linting passes
  • a test and/or benchmark is included
  • documentation is changed or added
  • the commit message follows commit guidelines
Affected core subsystem(s)
  • child-process
Description of change

The flushStdio() checks if there are readable handlers attached to the stdio streams to prevent data loss but it doesn't check if there are piped consumers. Change it so that it checks pipesCount too.

I also fixed the previous testcase on the same issue to actually catch the regression as it would previously pass regardless of what flushStdio was doing.

Fixes #7184

While commit 12274a5 fixed data loss when a readable event handler is
attached, the problem still exists when the stdio stream has a piped
consumer that doesn't read fast enough.

Signed-off-by: Petros Angelatos <[email protected]>
This commit prevents child process stdio streams from being
automatically flushed on child process exit/close if a piped consumer
has been attached at the time of exit.

Without this, child process stdio data can be lost if the process
exits quickly and the piped consumer hasn't had the chance to read the
remaining data.

Fixes: nodejs#7184
Signed-off-by: Petros Angelatos <[email protected]>
In order for the testcase to fail, the calls to read() must be done
after 'exit' is emitted and after flushStdio has been called.

With this change, the testcase will catch any regressions on this
issue.

Signed-off-by: Petros Angelatos <[email protected]>
@nodejs-github-bot nodejs-github-bot added the child_process Issues and PRs related to the child_process subsystem. label Jun 7, 2016
@petrosagg petrosagg changed the title Child process stdio flush Fix child process stdio data loss with slow piped consumers Jun 7, 2016
@addaleax
Copy link
Member

addaleax commented Jun 7, 2016

Hm, as #7184 seems like a duplicate of #7159, this is probably unnecessary as there’s already a fix available at the streams level (i.e. while this may work for child process output, the bug theoretically affects any pipe() where the readable gets resume()d manually).

let buf;
while (buf = this.read())
buffer.push(buf);
});
Copy link
Member

Choose a reason for hiding this comment

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

Why is this change necessary?

Copy link
Author

Choose a reason for hiding this comment

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

This testcase was added to cover the issue fixed here: balena-io-experimental@12274a5

But the testcase passes even if the change of that commit is reverted. So I just fixed the testcase to reflect what was actually fixed there.

Copy link
Author

Choose a reason for hiding this comment

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

Will PR this separately

Copy link
Member

@addaleax addaleax Jun 7, 2016

Choose a reason for hiding this comment

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

@petrosagg Can confirm that this test case worked even before 12274a5 – nice catch! A separate PR seems like a good idea, yep

@petrosagg
Copy link
Author

Confirmed that this issue is fixed in #7160

@petrosagg petrosagg closed this Jun 7, 2016
@addaleax
Copy link
Member

addaleax commented Jun 8, 2016

@petrosagg I’d like to get both of your changes to the tests in… are you interested in PRing yourself?

@petrosagg
Copy link
Author

@addaleax PRed here #7257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

child-process: data loss with piped stdout
3 participants