Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a9a2dd3

Browse filesBrowse files
ronagdanielleadams
authored andcommitted
http: don't cork noop .end()
Calling .end() a second time should be a noop and not leave the socket corked. Fixes: #36620 PR-URL: #36633 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Danielle Adams <adamzdanielle@gmail.com>
1 parent e8bb1f7 commit a9a2dd3
Copy full SHA for a9a2dd3

File tree

Expand file treeCollapse file tree

2 files changed

+12
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-4
lines changed
Open diff view settings
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,17 +819,18 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
819819
encoding = null;
820820
}
821821

822-
if (this.socket) {
823-
this.socket.cork();
824-
}
825-
826822
if (chunk) {
827823
if (this.finished) {
828824
onError(this,
829825
new ERR_STREAM_WRITE_AFTER_END(),
830826
typeof callback !== 'function' ? nop : callback);
831827
return this;
832828
}
829+
830+
if (this.socket) {
831+
this.socket.cork();
832+
}
833+
833834
write_(this, chunk, encoding, null, true);
834835
} else if (this.finished) {
835836
if (typeof callback === 'function') {
@@ -841,6 +842,10 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
841842
}
842843
return this;
843844
} else if (!this._header) {
845+
if (this.socket) {
846+
this.socket.cork();
847+
}
848+
844849
this._contentLength = 0;
845850
this._implicitHeader();
846851
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-outgoing-end-multiple.js
+3Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.