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 387d92f

Browse filesBrowse files
rickyescodebytere
authored andcommitted
http: onFinish will not be triggered again when finished
PR-URL: #35845 Fixes: #35833 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 8ae3ffe commit 387d92f
Copy full SHA for 387d92f

File tree

Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Open diff view settings
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,12 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
814814
}
815815

816816
if (chunk) {
817+
if (this.finished) {
818+
onError(this,
819+
new ERR_STREAM_WRITE_AFTER_END(),
820+
typeof callback !== 'function' ? nop : callback);
821+
return this;
822+
}
817823
write_(this, chunk, encoding, null, true);
818824
} else if (this.finished) {
819825
if (typeof callback === 'function') {
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
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ const common = require('../common');
33
const assert = require('assert');
44
const http = require('http');
55

6+
const onWriteAfterEndError = common.mustCall((err) => {
7+
assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END');
8+
}, 2);
9+
610
const server = http.createServer(common.mustCall(function(req, res) {
711
res.end('testing ended state', common.mustCall());
8-
res.end(common.mustCall());
12+
res.end(common.mustCall((err) => {
13+
assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED');
14+
}));
15+
res.end('end', onWriteAfterEndError);
16+
res.on('error', onWriteAfterEndError);
917
res.on('finish', common.mustCall(() => {
1018
res.end(common.mustCall((err) => {
1119
assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.