Skip to content

Fix two missing async hooks destroy calls

Supersedes https://github.com/nodejs/node/pull/23201 and https://github.com/nodejs/node/pull/23263 due to feedback from @addaleax in #23201.

  1. Add a missing destroy for HTTP socket when the agent gets reused
  2. Avoid duplicate call to AsyncWrap::Reset for HTTP parsers (each time a new parser was created, AsyncReset was being called via the C++ Parser class constructor (super constructor AsyncWrap) and also via Parser::Reinitialize).
  3. Add missing destroy for HTTP parsers when they are being reused.

Fixes: #19859 (closed)

Reasoning: When calling asyncReset, we need to be aware that this will overwrite the AsyncWrap's asyncId, for which we might have emitted an init. The asyncId used for that init is then lost, thus, a destroy event will never be emitted for this "old" asyncId. The added emitDestroy makes sure that a matching destroy event is emitted before we assign the new asyncId in asyncReset.

Test cases have been added for all three items - all of these tests fail without the changes in production code.

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