GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — console: avoid adding infinite error listeners · nodejs/node@bed0560

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • console.js
  • test/parallel
    • test-console-log-stdio-broken-dest.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/console.js‎

Copy file name to clipboardExpand all lines: lib/console.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ function createWriteErrorHandler(stream) {
8383
// an `error` event. Adding a `once` listener will keep that error
8484
// from becoming an uncaught exception, but since the handler is
8585
// removed after the event, non-console.* writes won’t be affected.
86-
stream.once('error', noop);
86+
// we are only adding noop if there is no one else listening for 'error'
87+
if (stream.listenerCount('error') === 0) {
88+
stream.on('error', noop);
89+
}
8790
}
8891
};
8992
}
Collapse file

‎test/parallel/test-console-log-stdio-broken-dest.js‎

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { Writable } = require('stream');
5+
const { Console } = require('console');
6+
const { EventEmitter } = require('events');
7+
8+
const stream = new Writable({
9+
write(chunk, enc, cb) {
10+
cb();
11+
},
12+
writev(chunks, cb) {
13+
setTimeout(cb, 10, new Error('kaboom'));
14+
}
15+
});
16+
const myConsole = new Console(stream, stream);
17+
18+
process.on('warning', common.mustNotCall);
19+
20+
stream.cork();
21+
for (let i = 0; i < EventEmitter.defaultMaxListeners + 1; i++) {
22+
myConsole.log('a message');
23+
}
24+
stream.uncork();

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.