Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/internal/streams/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function constructNT(stream) {
} else if (err) {
errorOrDestroy(stream, err, true);
} else {
process.nextTick(emitConstructNT, stream);
stream.emit(kConstruct);
}
}

Expand All @@ -304,10 +304,6 @@ function constructNT(stream) {
}
}

function emitConstructNT(stream) {
stream.emit(kConstruct);
}

function isRequest(stream) {
return stream?.setHeader && typeof stream.abort === 'function';
}
Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-fs-writestream-open-write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const common = require('../common');
const tmpdir = require('../common/tmpdir');
const { strictEqual } = require('assert');
const { join } = require('path');
const fs = require('fs');

// Regression test for https://github.com/nodejs/node/issues/51993

tmpdir.refresh();

const file = join(tmpdir.path, `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);
}));