http: fix http client leaky with double response · nodejs/node@157e1f1 · GitHub
Skip to content

Commit 157e1f1

Browse files
theanarkhaduh95
authored andcommitted
http: fix http client leaky with double response
PR-URL: #60062 Fixes: #60025 Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 0c130d0 commit 157e1f1

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

lib/_http_client.js

Lines changed: 9 additions & 1 deletion

lib/_http_common.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const {
4141
} = incoming;
4242

4343
const kIncomingMessage = Symbol('IncomingMessage');
44+
const kSkipPendingData = Symbol('SkipPendingData');
4445
const kOnMessageBegin = HTTPParser.kOnMessageBegin | 0;
4546
const kOnHeaders = HTTPParser.kOnHeaders | 0;
4647
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
@@ -126,7 +127,7 @@ function parserOnBody(b) {
126127
const stream = this.incoming;
127128

128129
// If the stream has already been removed, then drop it.
129-
if (stream === null)
130+
if (stream === null || stream[kSkipPendingData])
130131
return;
131132

132133
// Pretend this was the result of a stream._read call.
@@ -141,7 +142,7 @@ function parserOnMessageComplete() {
141142
const parser = this;
142143
const stream = parser.incoming;
143144

144-
if (stream !== null) {
145+
if (stream !== null && !stream[kSkipPendingData]) {
145146
stream.complete = true;
146147
// Emit any trailing headers.
147148
const headers = parser._headers;
@@ -310,4 +311,5 @@ module.exports = {
310311
HTTPParser,
311312
isLenient,
312313
prepareError,
314+
kSkipPendingData,
313315
};
Lines changed: 44 additions & 0 deletions

0 commit comments

Comments
 (0)