Skip to content

async_wrap: schedule destroy hook as unref

Since the DestroyAsyncIdsCallback in Node.js can be scheduled as a result of GC, that means that it can accidentally keep the event loop open when it shouldn't. Replace SetImmediate with the newly introduced SetUnrefImmediate and in addition introduce RunBeforeExit callbacks, of which DestroyAsyncIdsCallback is now the first. These callbacks will run before the beforeExit event is emitted (which will now only be emitted if the event loop is still not active).

Fixes: https://github.com/nodejs/node/issues/18190

Linux CI to assess whether this fixes the above (all green): https://ci.nodejs.org/job/node-test-commit-linux/15673/ https://ci.nodejs.org/job/node-test-commit-linux/15674/ https://ci.nodejs.org/job/node-test-commit-linux/15675/

CI: https://ci.nodejs.org/job/node-test-pull-request/12615/ https://ci.nodejs.org/job/node-test-commit/15516/ https://ci.nodejs.org/job/node-test-commit/15517/

CitGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1212/

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

async_wrap

Merge request reports

Loading