console: avoid adding infinite error listeners#16770
console: avoid adding infinite error listeners#16770mcollina wants to merge 1 commit intonodejs:masterfrom
Conversation
|
@gibfahn this needs to go into node 8. |
There was a problem hiding this comment.
Maybe the loop limit can be something like EventEmitter.defaultMaxListeners + 1 instead of a hardcoded value?
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 |
| // 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.
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 <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
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 <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
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 <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
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