mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
console: don't attach unnecessary error handlers
A noop error handler is attached to the console's stream on write. The handler is then immediately removed after the write. This commit skips adding the error handler if one already exists. PR-URL: https://github.com/nodejs/node/pull/27691 Fixes: https://github.com/nodejs/node/issues/27687 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
1 parent
6984ca1c2f
commit
da102cda54
2 files changed
+18
-1
No files matched your search
@@ -231,7 +231,8 @@ Console.prototype[kWriteToConsole] = function(streamSymbol, string) {
|
||||
// handle both situations.
|
||||
try {
|
||||
// Add and later remove a noop error handler to catch synchronous errors.
|
||||
stream.once('error', noop);
|
||||
if (stream.listenerCount('error') === 0)
|
||||
stream.once('error', noop);
|
||||
|
||||
stream.write(string, errorHandler);
|
||||
} catch (e) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const { Worker, isMainThread } = require('worker_threads');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
if (isMainThread) {
|
||||
process.on('warning', common.mustNotCall('unexpected warning'));
|
||||
|
||||
for (let i = 0; i < EventEmitter.defaultMaxListeners; ++i) {
|
||||
const worker = new Worker(__filename);
|
||||
|
||||
worker.on('exit', common.mustCall(() => {
|
||||
console.log('a'); // This console.log() is part of the test.
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user