Skip to content

Commit b2834ce

Browse files
bcoeaddaleax
authored andcommitted
process: fix call process.reallyExit, vs., binding
Some user-land modules, e.g., nyc, mocha, currently rely on patching process.reallyExit. PR-URL: #25655 Fixes: #25650 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 55768c0 commit b2834ce

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/internal/process/per_thread.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ function wrapProcessMethods(binding) {
149149
process._exiting = true;
150150
process.emit('exit', process.exitCode || 0);
151151
}
152-
binding.reallyExit(process.exitCode || 0);
152+
// FIXME(joyeecheung): This is an undocumented API that gets monkey-patched
153+
// in the user land. Either document it, or deprecate it in favor of a
154+
// better public alternative.
155+
process.reallyExit(process.exitCode || 0);
153156
}
154157

155158
function kill(pid, sig) {
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
5+
// ensure that the reallyExit hook is executed.
6+
// see: https://github.com/nodejs/node/issues/25650
7+
if (process.argv[2] === 'subprocess') {
8+
process.reallyExit = function() {
9+
console.info('really exited');
10+
};
11+
process.exit();
12+
} else {
13+
const { spawnSync } = require('child_process');
14+
const out = spawnSync(process.execPath, [__filename, 'subprocess']);
15+
const observed = out.output[1].toString('utf8').trim();
16+
assert.strictEqual(observed, 'really exited');
17+
}

0 commit comments

Comments
 (0)