Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 190ddce

Browse filesBrowse files
ronagdanielleadams
authored andcommitted
stream: only use legacy close listeners if not willEmitClose
Some streams that willEmitClose unecessarily fallback to legacy events. PR-URL: #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>
1 parent 651e7d2 commit 190ddce
Copy full SHA for 190ddce

File tree

Expand file treeCollapse file tree

2 files changed

+27
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/end-of-stream.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/end-of-stream.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ function eos(stream, options, callback) {
129129

130130
if (isRequest(stream)) {
131131
stream.on('complete', onfinish);
132-
stream.on('abort', onclose);
132+
if (!willEmitClose) {
133+
stream.on('abort', onclose);
134+
}
133135
if (stream.req) onrequest();
134136
else stream.on('request', onrequest);
135137
} else if (writable && !wState) { // legacy streams
@@ -138,7 +140,7 @@ function eos(stream, options, callback) {
138140
}
139141

140142
// Not all streams will emit 'close' after 'aborted'.
141-
if (typeof stream.aborted === 'boolean') {
143+
if (!willEmitClose && typeof stream.aborted === 'boolean') {
142144
stream.on('aborted', onclose);
143145
}
144146

Collapse file

‎test/parallel/test-stream-finished.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-finished.js
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,26 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
492492
.on('response', common.mustCall());
493493
});
494494
}
495+
496+
497+
{
498+
const w = new Writable({
499+
write(chunk, encoding, callback) {
500+
process.nextTick(callback);
501+
}
502+
});
503+
w.aborted = false;
504+
w.end();
505+
let closed = false;
506+
w.on('finish', () => {
507+
assert.strictEqual(closed, false);
508+
w.emit('aborted');
509+
});
510+
w.on('close', common.mustCall(() => {
511+
closed = true;
512+
}));
513+
514+
finished(w, common.mustCall(() => {
515+
assert.strictEqual(closed, true);
516+
}));
517+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.