Skip to content

Commit

Permalink
stream: finished on closed OutgoingMessage
Browse files Browse the repository at this point in the history
finished should invoke callback on closed OutgoingMessage the
same way as for regular streams.

Fixes: #34301
  • Loading branch information
ronag committed Jul 12, 2020
1 parent 4e3f6f3 commit cd753c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_STREAM_PREMATURE_CLOSE
} = require('internal/errors').codes;
const { kClosed } = require('internal/http');
const { once } = require('internal/util');

function isRequest(stream) {
Expand Down Expand Up @@ -147,7 +148,7 @@ function eos(stream, opts, callback) {
if (opts.error !== false) stream.on('error', onerror);
stream.on('close', onclose);

const closed = (
const closed = stream[kClosed] === true || (
(wState && wState.closed) ||
(rState && rState.closed) ||
(wState && wState.errorEmitted) ||
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-stream-finished.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const assert = require('assert');
const EE = require('events');
const fs = require('fs');
const { promisify } = require('util');
const http = require('http');

{
const rs = new Readable({
Expand Down Expand Up @@ -480,3 +481,21 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
finished(p, common.mustNotCall());
}));
}

{
const server = http.createServer((req, res) => {
res.on('close', () => {
finished(res, common.mustCall(() => {
server.close();
}));
});
res.end();
})
.listen(0, function() {
http.request({
method: 'GET',
port: this.address().port
}).end()
.on('response', common.mustCall());
});
}

0 comments on commit cd753c4

Please sign in to comment.