mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
stream: only use legacy close listeners if not willEmitClose
Some streams that willEmitClose unecessarily fallback to legacy events. PR-URL: https://github.com/nodejs/node/pull/36649 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
committed by
Node.js GitHub Bot
parent
a5b43e9404
commit
faee7399b2
@@ -129,7 +129,9 @@ function eos(stream, options, callback) {
|
||||
|
||||
if (isRequest(stream)) {
|
||||
stream.on('complete', onfinish);
|
||||
stream.on('abort', onclose);
|
||||
if (!willEmitClose) {
|
||||
stream.on('abort', onclose);
|
||||
}
|
||||
if (stream.req) onrequest();
|
||||
else stream.on('request', onrequest);
|
||||
} else if (writable && !wState) { // legacy streams
|
||||
@@ -138,7 +140,7 @@ function eos(stream, options, callback) {
|
||||
}
|
||||
|
||||
// Not all streams will emit 'close' after 'aborted'.
|
||||
if (typeof stream.aborted === 'boolean') {
|
||||
if (!willEmitClose && typeof stream.aborted === 'boolean') {
|
||||
stream.on('aborted', onclose);
|
||||
}
|
||||
|
||||
|
||||
@@ -492,3 +492,26 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
|
||||
.on('response', common.mustCall());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
const w = new Writable({
|
||||
write(chunk, encoding, callback) {
|
||||
process.nextTick(callback);
|
||||
}
|
||||
});
|
||||
w.aborted = false;
|
||||
w.end();
|
||||
let closed = false;
|
||||
w.on('finish', () => {
|
||||
assert.strictEqual(closed, false);
|
||||
w.emit('aborted');
|
||||
});
|
||||
w.on('close', common.mustCall(() => {
|
||||
closed = true;
|
||||
}));
|
||||
|
||||
finished(w, common.mustCall(() => {
|
||||
assert.strictEqual(closed, true);
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user