Skip to content

Commit 4cc48de

Browse files
committed
http: don't cork noop .end()
Calling .end() a second time should be a noop and not leave the socket corked. Fixes: #36620
1 parent 7303afb commit 4cc48de

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/_http_outgoing.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,17 +810,18 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
810810
encoding = null;
811811
}
812812

813-
if (this.socket) {
814-
this.socket.cork();
815-
}
816-
817813
if (chunk) {
818814
if (this.finished) {
819815
onError(this,
820816
new ERR_STREAM_WRITE_AFTER_END(),
821817
typeof callback !== 'function' ? nop : callback);
822818
return this;
823819
}
820+
821+
if (this.socket) {
822+
this.socket.cork();
823+
}
824+
824825
write_(this, chunk, encoding, null, true);
825826
} else if (this.finished) {
826827
if (typeof callback === 'function') {

test/parallel/test-http-outgoing-end-multiple.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ const onWriteAfterEndError = common.mustCall((err) => {
99

1010
const server = http.createServer(common.mustCall(function(req, res) {
1111
res.end('testing ended state', common.mustCall());
12+
assert.strictEqual(res.writableCorked, 0);
1213
res.end(common.mustCall((err) => {
1314
assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED');
1415
}));
16+
assert.strictEqual(res.writableCorked, 0);
1517
res.end('end', onWriteAfterEndError);
18+
assert.strictEqual(res.writableCorked, 0);
1619
res.on('error', onWriteAfterEndError);
1720
res.on('finish', common.mustCall(() => {
1821
res.end(common.mustCall((err) => {

0 commit comments

Comments
 (0)