Add regression tests for the case in which an async_hook is enabled inside a Worker thread and `process.exit()` is called during the async part of an async function. This commit includes multiple tests that seem like they should all crash in a similar way, but interestingly don’t. In particular, it’s surprising that the presence of a statement after `process.exit()` in a function has an effect on the kind of crash that’s being exhibited (V8 DCHECK vs. assertion in our own code) and the circumstances under which it crashes (e.g. the -1 and -2 tests can be “fixed” by reverting 13c5a1629cd025b, although they should have the same behavior as the -3 and -4 tests). PR-URL: https://github.com/nodejs/node/pull/33347 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
22 lines
601 B
JavaScript
22 lines
601 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const { Worker } = require('worker_threads');
|
|
|
|
// Like test-async-hooks-worker-promise.js but with the `await` and `createHook`
|
|
// lines switched, because that resulted in different assertion failures
|
|
// (one a Node.js assertion and one a V8 DCHECK) and it seems prudent to
|
|
// cover both of those failures.
|
|
|
|
const w = new Worker(`
|
|
const { createHook } = require('async_hooks');
|
|
|
|
setImmediate(async () => {
|
|
await 0;
|
|
createHook({ init() {} }).enable();
|
|
process.exit();
|
|
});
|
|
`, { eval: true });
|
|
|
|
w.postMessage({});
|
|
w.on('exit', common.mustCall());
|