Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test: forbid common.mustCall*() in process exit handlers
`common.mustCall()` and `common.mustCallAtLeast()` need to be called
before process exit handlers to work because checks are done inside a
process exit handler. Detect if being used inside a process exit handler
and throw.

PR-URL: #17453
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Dec 12, 2017
1 parent 85e6271 commit 0ade488
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/common/index.js
Expand Up @@ -493,6 +493,8 @@ exports.mustCallAtLeast = function(fn, minimum) {
};

function _mustCallInner(fn, criteria = 1, field) {
if (process._exiting)
throw new Error('Cannot use common.mustCall*() in process exit handler');
if (typeof fn === 'number') {
criteria = fn;
fn = noop;
Expand Down

0 comments on commit 0ade488

Please sign in to comment.