stream: do not defer construction by one microtick

Fixes: https://github.com/nodejs/node/issues/51993
PR-URL: https://github.com/nodejs/node/pull/52005
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Matteo Collina authored and Michaël Zasso committed 2024-03-08 14:35:30 +01:00
1 parent 73025c4dec
commit cb85073709
2 files changed
+29 -5

No files matched your search

+1 -5
View File
@@ -291,7 +291,7 @@ function constructNT(stream) {
} else if (err) {
errorOrDestroy(stream, err, true);
} else {
process.nextTick(emitConstructNT, stream);
stream.emit(kConstruct);
}
}
@@ -304,10 +304,6 @@ function constructNT(stream) {
}
}
function emitConstructNT(stream) {
stream.emit(kConstruct);
}
function isRequest(stream) {
return stream?.setHeader && typeof stream.abort === 'function';
}
@@ -0,0 +1,28 @@
'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const { strictEqual } = require('assert');
const fs = require('fs');
// Regression test for https://github.com/nodejs/node/issues/51993
tmpdir.refresh();
const file = tmpdir.resolve('test-fs-writestream-open-write.txt');
const w = fs.createWriteStream(file);
w.on('open', common.mustCall(() => {
w.write('hello');
process.nextTick(() => {
w.write('world');
w.end();
});
}));
w.on('close', common.mustCall(() => {
strictEqual(fs.readFileSync(file, 'utf8'), 'helloworld');
fs.unlinkSync(file);
}));