Skip to content

Commit 16d8cd5

Browse files
mcollinarichardlau
authored andcommitted
stream: do not defer construction by one microtick
Fixes: #51993 PR-URL: #52005 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 905c48f commit 16d8cd5

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

‎lib/internal/streams/destroy.js‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ function constructNT(stream){
291291
}elseif(err){
292292
errorOrDestroy(stream,err,true);
293293
}else{
294-
process.nextTick(emitConstructNT,stream);
294+
stream.emit(kConstruct);
295295
}
296296
}
297297

@@ -304,10 +304,6 @@ function constructNT(stream){
304304
}
305305
}
306306

307-
functionemitConstructNT(stream){
308-
stream.emit(kConstruct);
309-
}
310-
311307
functionisRequest(stream){
312308
returnstream?.setHeader&&typeofstream.abort==='function';
313309
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
consttmpdir=require('../common/tmpdir');
5+
const{ strictEqual }=require('assert');
6+
constfs=require('fs');
7+
8+
// Regression test for https://github.com/nodejs/node/issues/51993
9+
10+
tmpdir.refresh();
11+
12+
constfile=tmpdir.resolve('test-fs-writestream-open-write.txt');
13+
14+
constw=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)