Skip to content

Commit 7b5c8e1

Browse files
committed
stream: fix fd is null when calling clearBuffer
1 parent a3ee187 commit 7b5c8e1

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/internal/streams/writable.js

Lines changed: 2 additions & 1 deletion
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)) !== kBuffered ||
737+
(state[kState] & (kDestroyed | kBufferProcessing | kCorked | kConstructed)) !== kConstructed) {
737738
return;
738739
}
739740

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 tmpdir = require('../common/tmpdir');
10+
11+
const filepath = tmpdir.resolve('write_stream.txt');
12+
tmpdir.refresh();
13+
14+
const data = 'data';
15+
16+
const fileWriteStream = fs.createWriteStream(filepath);
17+
18+
fileWriteStream.on('finish', () => {
19+
const writtenData = fs.readFileSync(filepath, 'utf8');
20+
assert.strictEqual(writtenData, data);
21+
});
22+
fileWriteStream.cork();
23+
fileWriteStream.write(data, common.mustCall());
24+
fileWriteStream.uncork();
25+
fileWriteStream.end();

0 commit comments

Comments
 (0)