-
Notifications
You must be signed in to change notification settings - Fork 30k
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
console: avoid adding infinite error listeners #16770
Conversation
@gibfahn this needs to go into node 8. |
process.on('warning', common.mustNotCall); | ||
|
||
stream.cork(); | ||
for (let i = 0; i < 20; i++) { |
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.
Maybe the loop limit can be something like EventEmitter.defaultMaxListeners + 1
instead of a hardcoded value?
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.
updated
If the console destination is a unix pipe (net.Socket), write() is async. If the destination is broken, we are adding an 'error' event listener to avoid a process crash. This PR makes sure that we are adding that listener only once. Fixes: nodejs#16767
So this seems serious enough that it should go into the next Node 8.x release (planned for Tuesday). Thoughts @nodejs/lts? If so it'd be great to get this landed ASAP. |
@gibfahn I think it’s okay to include this in an LTS without letting it sit in a Current release, but tbh that’s more because of a low chance of breaking anything rather than any other reason. |
@addaleax do you think it's worth rushing the landing of this to get it into the next release? |
@gibfahn Can’t tell whether it’s worth it, but I think it’s the kind of bugfix that shouldn’t need to wait 4 weeks to be fixed due to process… |
I think it should go in 8 asap. As @addaleax said, this is a low risk change. When is the next release planned? |
And after that? |
Are we ok to fast-track this? cc @nodejs/tsc |
Probably another couple of weeks. |
Can this code get confused if the end-user adds an error handler, and then later removes it? That is, the error handler count is greater than 0, but only briefly? |
Definitely good with getting this landed quickly. It's likely safe to let it stand for a week or two before landing in LTS. |
no. Emitting This condition happens only when |
@@ -83,7 +83,10 @@ function createWriteErrorHandler(stream) { | |||
// an `error` event. Adding a `once` listener will keep that error | |||
// from becoming an uncaught exception, but since the handler is | |||
// removed after the event, non-console.* writes won’t be affected. | |||
stream.once('error', noop); | |||
// we are only adding noop if there is no one else listening for 'error' |
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.
if this can happen only with writev()
, its worth mentioning specifically in the comment
Landed as d82bedc. |
If the console destination is a unix pipe (net.Socket), write() is async. If the destination is broken, we are adding an 'error' event listener to avoid a process crash. This PR makes sure that we are adding that listener only once. Fixes: #16767 PR-URL: #16770 Fixes: #16767 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
If the console destination is a unix pipe (net.Socket), write() is async. If the destination is broken, we are adding an 'error' event listener to avoid a process crash. This PR makes sure that we are adding that listener only once. Fixes: #16767 PR-URL: #16770 Fixes: #16767 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
If the console destination is a unix pipe (net.Socket), write() is async. If the destination is broken, we are adding an 'error' event listener to avoid a process crash. This PR makes sure that we are adding that listener only once. Fixes: #16767 PR-URL: #16770 Fixes: #16767 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
Notable Changes: - **console**: - avoid adding infinite error listeners (Matteo Collina) [#16770](https://github.com/nodejs/n de/pull/16770) - **http2**: - improve errors thrown in header validation (Joyee Cheung) [#16718](https://github.com/nodej s/node/pull/16718) PR-URL: #17204
Notable Changes: - **console**: - avoid adding infinite error listeners (Matteo Collina) [#16770](https://github.com/nodejs/n de/pull/16770) - **http2**: - improve errors thrown in header validation (Joyee Cheung) [#16718](https://github.com/nodej s/node/pull/16718) PR-URL: #17204
If the console destination is a unix pipe (net.Socket), write() is
async. If the destination is broken, we are adding an 'error' event
listener to avoid a process crash. This PR makes sure that we are adding
that listener only once.
Fixes: #16767
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
console