Skip to content

Commit 756ac65

Browse files
committed
http: fix crash for sync write errors during header parsing
Fix a crash that occurs when `parser.finish()` is called during `parser.execute()`. In this particular case, this happened because a 100 continue response is a place in which `.end()` can be called which can in turn lead to a write error, which is emitted synchronously, thus inside the outer `parser.execute()` call. Resolve that by delaying the `parser.finish()` call until after the `parser.execute()` call is done. This only affects v12.x, because on later versions, errors are not emitted synchronously. PR-URL: #34251 Fixes: #15102 Fixes: #34016 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
1 parent 65b7bf4 commit 756ac65

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/_http_client.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,12 @@ function socketErrorListener(err) {
431431

432432
const parser = socket.parser;
433433
if (parser) {
434-
parser.finish();
435-
freeParser(parser, req, socket);
434+
// Use process.nextTick() on v12.x since 'error' events might be
435+
// emitted synchronously from e.g. a failed write() call on the socket.
436+
process.nextTick(() => {
437+
parser.finish();
438+
freeParser(parser, req, socket);
439+
});
436440
}
437441

438442
// Ensure that no further data will come out of the socket

0 commit comments

Comments
 (0)