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 270b519

Browse filesBrowse files
mcollinarichardlau
authored andcommitted
stream: do not defer construction by one microtick
Fixes: #51993 PR-URL: #52005 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent c70383b commit 270b519
Copy full SHA for 270b519

2 files changed

+29-5Lines changed: 29 additions & 5 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/destroy.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/destroy.js
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ function constructNT(stream) {
267267
} else if (err) {
268268
errorOrDestroy(stream, err, true);
269269
} else {
270-
process.nextTick(emitConstructNT, stream);
270+
stream.emit(kConstruct);
271271
}
272272
}
273273

@@ -280,10 +280,6 @@ function constructNT(stream) {
280280
}
281281
}
282282

283-
function emitConstructNT(stream) {
284-
stream.emit(kConstruct);
285-
}
286-
287283
function isRequest(stream) {
288284
return stream?.setHeader && typeof stream.abort === 'function';
289285
}
Collapse file
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const tmpdir = require('../common/tmpdir');
5+
const { strictEqual } = require('assert');
6+
const fs = require('fs');
7+
8+
// Regression test for https://github.com/nodejs/node/issues/51993
9+
10+
tmpdir.refresh();
11+
12+
const file = tmpdir.resolve('test-fs-writestream-open-write.txt');
13+
14+
const w = fs.createWriteStream(file);
15+
16+
w.on('open', common.mustCall(() => {
17+
w.write('hello');
18+
19+
process.nextTick(() => {
20+
w.write('world');
21+
w.end();
22+
});
23+
}));
24+
25+
w.on('close', common.mustCall(() => {
26+
strictEqual(fs.readFileSync(file, 'utf8'), 'helloworld');
27+
fs.unlinkSync(file);
28+
}));

0 commit comments

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