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

Closed
wants to merge 1 commit into
base: master
from

Conversation

@mcollina
Member

mcollina commented Nov 5, 2017

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

console

@mcollina mcollina requested review from mscdex, jasnell and addaleax Nov 5, 2017

@jasnell

jasnell approved these changes Nov 5, 2017

@mcollina

This comment has been minimized.

Show comment
Hide comment
@mcollina

mcollina Nov 5, 2017

Member

@gibfahn this needs to go into node 8.

Member

mcollina commented Nov 5, 2017

@gibfahn this needs to go into node 8.

@cjihrig

cjihrig approved these changes Nov 5, 2017

console: avoid adding infinite error listeners
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
@mcollina

This comment has been minimized.

Show comment
Hide comment
@gibfahn

This comment has been minimized.

Show comment
Hide comment
@gibfahn

gibfahn Nov 5, 2017

Member

@gibfahn this needs to go into node 8.

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.

Member

gibfahn commented Nov 5, 2017

@gibfahn this needs to go into node 8.

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.

@addaleax

This comment has been minimized.

Show comment
Hide comment
@addaleax

addaleax Nov 5, 2017

Member

@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.

Member

addaleax commented Nov 5, 2017

@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.

@gibfahn

This comment has been minimized.

Show comment
Hide comment
@gibfahn

gibfahn Nov 5, 2017

Member

@addaleax do you think it's worth rushing the landing of this to get it into the next release?

Member

gibfahn commented Nov 5, 2017

@addaleax do you think it's worth rushing the landing of this to get it into the next release?

@addaleax

This comment has been minimized.

Show comment
Hide comment
@addaleax

addaleax Nov 5, 2017

Member

@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…

Member

addaleax commented Nov 5, 2017

@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…

@mcollina

This comment has been minimized.

Show comment
Hide comment
@mcollina

mcollina Nov 5, 2017

Member

I think it should go in 8 asap. As @addaleax said, this is a low risk change. When is the next release planned?

Member

mcollina commented Nov 5, 2017

I think it should go in 8 asap. As @addaleax said, this is a low risk change. When is the next release planned?

@gibfahn

This comment has been minimized.

Show comment
Hide comment
@gibfahn

gibfahn Nov 5, 2017

Member

@mcollina Tuesday, see #16783

Member

gibfahn commented Nov 5, 2017

@mcollina Tuesday, see #16783

@mcollina

This comment has been minimized.

Show comment
Hide comment
@mcollina

mcollina Nov 6, 2017

Member

And after that?
If we are ok with it we can land it tomorrow.

Member

mcollina commented Nov 6, 2017

And after that?
If we are ok with it we can land it tomorrow.

@lpinca

lpinca approved these changes Nov 6, 2017

@mcollina

This comment has been minimized.

Show comment
Hide comment
@mcollina

mcollina Nov 6, 2017

Member

Are we ok to fast-track this? cc @nodejs/tsc

Member

mcollina commented Nov 6, 2017

Are we ok to fast-track this? cc @nodejs/tsc

@gibfahn

This comment has been minimized.

Show comment
Hide comment
@gibfahn

gibfahn Nov 6, 2017

Member

And after that?

Probably another couple of weeks.

Member

gibfahn commented Nov 6, 2017

And after that?

Probably another couple of weeks.

@sam-github

This comment has been minimized.

Show comment
Hide comment
@sam-github

sam-github Nov 6, 2017

Member

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?

Member

sam-github commented Nov 6, 2017

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?

@jasnell

This comment has been minimized.

Show comment
Hide comment
@jasnell

jasnell Nov 6, 2017

Member

Definitely good with getting this landed quickly. It's likely safe to let it stand for a week or two before landing in LTS.

Member

jasnell commented Nov 6, 2017

Definitely good with getting this landed quickly. It's likely safe to let it stand for a week or two before landing in LTS.

@mcollina

This comment has been minimized.

Show comment
Hide comment
@mcollina

mcollina Nov 6, 2017

Member

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?

no. Emitting 'error' is done only once, and it is just deferred to the next tick: https://github.com/nodejs/node/blob/master/lib/_stream_writable.js#L398.

This condition happens only when _writev is involved, as multiple writes are going to error at the same time.

Member

mcollina commented Nov 6, 2017

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?

no. Emitting 'error' is done only once, and it is just deferred to the next tick: https://github.com/nodejs/node/blob/master/lib/_stream_writable.js#L398.

This condition happens only when _writev is involved, as multiple writes are going to error at the same time.

@@ -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'

This comment has been minimized.

@sam-github

sam-github Nov 6, 2017

Member

if this can happen only with writev(), its worth mentioning specifically in the comment

@sam-github

sam-github Nov 6, 2017

Member

if this can happen only with writev(), its worth mentioning specifically in the comment

@mcollina

This comment has been minimized.

Show comment
Hide comment
@mcollina

mcollina Nov 8, 2017

Member

Landed as d82bedc.

Member

mcollina commented Nov 8, 2017

Landed as d82bedc.

@mcollina mcollina closed this Nov 8, 2017

@mcollina mcollina deleted the mcollina:fix-16767 branch Nov 8, 2017

mcollina added a commit that referenced this pull request Nov 8, 2017

console: avoid adding infinite error listeners
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>

gibfahn added a commit that referenced this pull request Nov 8, 2017

console: avoid adding infinite error listeners
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>

@gibfahn gibfahn added land-on-v8.x and removed lts-watch-v8.x labels Nov 8, 2017

evanlucas added a commit that referenced this pull request Nov 13, 2017

console: avoid adding infinite error listeners
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>

@evanlucas evanlucas referenced this pull request Nov 13, 2017

Merged

v9.2.0 proposal #16992

@gibfahn gibfahn referenced this pull request Nov 21, 2017

Merged

v8.9.2 proposal #17204

gibfahn added a commit that referenced this pull request Dec 5, 2017

2017-12-05, Version 8.9.2 'Carbon' (LTS)
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

gibfahn added a commit that referenced this pull request Dec 5, 2017

2017-12-05, Version 8.9.2 'Carbon' (LTS)
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

msoechting added a commit to hpicgs/node that referenced this pull request Feb 5, 2018

2017-12-05, Version 8.9.2 'Carbon' (LTS)
Notable Changes:

- **console**:
  - avoid adding infinite error listeners (Matteo Collina) [nodejs#16770](https://github.com/nodejs/n
de/pull/16770)
- **http2**:
  - improve errors thrown in header validation (Joyee Cheung) [nodejs#16718](https://github.com/nodej
s/node/pull/16718)

PR-URL: nodejs#17204

msoechting added a commit to hpicgs/node that referenced this pull request Feb 7, 2018

console: avoid adding infinite error listeners
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

PR-URL: nodejs#16770
Fixes: nodejs#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>

msoechting added a commit to hpicgs/node that referenced this pull request Feb 7, 2018

2017-12-05, Version 8.9.2 'Carbon' (LTS)
Notable Changes:

- **console**:
  - avoid adding infinite error listeners (Matteo Collina) [nodejs#16770](https://github.com/nodejs/n
de/pull/16770)
- **http2**:
  - improve errors thrown in header validation (Joyee Cheung) [nodejs#16718](https://github.com/nodej
s/node/pull/16718)

PR-URL: nodejs#17204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment