Skip to content

[v12.x] http: fix crash for sync write errors during header parsing

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.

Fixes: https://github.com/nodejs/node/issues/15102 Fixes: https://github.com/nodejs/node/issues/34016

test: add regression tests for HTTP parser crash

Since the tests only crash on v12.x, this commit adds separate regression tests.

Refs: https://github.com/nodejs/node/issues/15102 Refs: https://github.com/nodejs/node/issues/34016

[This is #34250, which this PR is blocked on.]

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Merge request reports

Loading