Skip to content

Commit

Permalink
fixup: merge nodejs#28720
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Sep 2, 2019
1 parent 27a9624 commit 5641590
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ function eos(stream, opts, callback) {
const onclose = () => {
let err;
if (readable && !readableEnded) {
if (!stream._readableState || !stream._readableState.ended)
readableEnded = stream.readableEnded ||
(stream._readableState && stream._readableState.endEmitted);

if (!readableEnded)
err = new ERR_STREAM_PREMATURE_CLOSE();
return callback.call(stream, err);
}
if (writable && !writableFinished) {
if (!stream._writableState || !stream._writableState.ended)
writableFinished = stream.writableFinished ||
(stream._writableState && stream._writableState.finished);

if (!writableFinished)
err = new ERR_STREAM_PREMATURE_CLOSE();
return callback.call(stream, err);
}
Expand Down
16 changes: 15 additions & 1 deletion test/parallel/test-stream-finished.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ const { promisify } = require('util');
}));
}

{
const rs = new Readable();

finished(rs, common.mustCall((err) => {
assert(err, 'premature close error');
}));

rs.push(null);
rs.emit('close');
rs.resume();
}

{
const rs = new Readable();

Expand All @@ -105,7 +117,9 @@ const { promisify } = require('util');
}));

rs.push(null);
rs.emit('close'); // Should not trigger an error
rs.on('end', common.mustCall(() => {
rs.emit('close'); // Should not trigger an error
}));
rs.resume();
}

Expand Down

0 comments on commit 5641590

Please sign in to comment.