-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Fix child process stdio data loss with slow piped consumers #7185
Conversation
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]>
let buf; | ||
while (buf = this.read()) | ||
buffer.push(buf); | ||
}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will PR this separately
There was a problem hiding this comment.
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
Confirmed that this issue is fixed in #7160 |
@petrosagg I’d like to get both of your changes to the tests in… are you interested in PRing yourself? |
Checklist
Affected core subsystem(s)
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 checkspipesCount
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