mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 20:09:32 +00:00

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: https://github.com/nodejs/node/issues/16767 PR-URL: https://github.com/nodejs/node/pull/16770 Fixes: https://github.com/nodejs/node/issues/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>
25 lines
545 B
JavaScript
25 lines
545 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { Writable } = require('stream');
|
|
const { Console } = require('console');
|
|
const { EventEmitter } = require('events');
|
|
|
|
const stream = new Writable({
|
|
write(chunk, enc, cb) {
|
|
cb();
|
|
},
|
|
writev(chunks, cb) {
|
|
setTimeout(cb, 10, new Error('kaboom'));
|
|
}
|
|
});
|
|
const myConsole = new Console(stream, stream);
|
|
|
|
process.on('warning', common.mustNotCall);
|
|
|
|
stream.cork();
|
|
for (let i = 0; i < EventEmitter.defaultMaxListeners + 1; i++) {
|
|
myConsole.log('a message');
|
|
}
|
|
stream.uncork();
|