Skip to content

Commit 8750070

Browse files
kylo5abyrichardlau
authored andcommitted
stream: fix fd is null when calling clearBuffer
PR-URL: #50994 Fixes: #50979 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Raz Luvaton <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
1 parent bd528c7 commit 8750070

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/internal/streams/writable.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,8 @@ function errorBuffer(state) {
733733

734734
// If there's something in the buffer waiting, then process it.
735735
function clearBuffer(stream, state) {
736-
if ((state[kState] & (kDestroyed | kBufferProcessing | kCorked | kBuffered)) !== kBuffered) {
736+
if ((state[kState] & (kDestroyed | kBufferProcessing | kCorked | kBuffered | kConstructed)) !==
737+
(kBuffered | kConstructed)) {
737738
return;
738739
}
739740

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
// Test 'uncork' for WritableStream.
4+
// Refs: https://github.com/nodejs/node/issues/50979
5+
6+
const common = require('../common');
7+
const fs = require('fs');
8+
const assert = require('assert');
9+
const test = require('node:test');
10+
const tmpdir = require('../common/tmpdir');
11+
12+
const filepath = tmpdir.resolve('write_stream.txt');
13+
tmpdir.refresh();
14+
15+
const data = 'data';
16+
17+
test('writable stream uncork', () => {
18+
const fileWriteStream = fs.createWriteStream(filepath);
19+
20+
fileWriteStream.on('finish', common.mustCall(() => {
21+
const writtenData = fs.readFileSync(filepath, 'utf8');
22+
assert.strictEqual(writtenData, data);
23+
}));
24+
fileWriteStream.cork();
25+
fileWriteStream.write(data, common.mustCall());
26+
fileWriteStream.uncork();
27+
fileWriteStream.end();
28+
});

0 commit comments

Comments
 (0)