Skip to content

Commit 41d0df6

Browse files
committedDec 6, 2024··
fix(core): fix process being prevented from exiting (#29240)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> The db cleanup handler does not exit the process and thus does not handle `SIGINT` properly. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Nx processes handle SIGINT properly. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit de8b189)
1 parent c071f84 commit 41d0df6

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed
 

‎packages/nx/bin/nx.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { performance } from 'perf_hooks';
2121
import { setupWorkspaceContext } from '../src/utils/workspace-context';
2222
import { daemonClient } from '../src/daemon/client/client';
2323
import { removeDbConnections } from '../src/utils/db-connection';
24+
import { signalToCode } from '../src/utils/exit-codes';
2425

2526
function main() {
2627
if (
@@ -275,12 +276,26 @@ const getLatestVersionOfNx = ((fn: () => string) => {
275276
return () => cache || (cache = fn());
276277
})(_getLatestVersionOfNx);
277278

278-
function nxCleanup() {
279+
function nxCleanup(signal?: NodeJS.Signals) {
279280
removeDbConnections();
281+
if (signal) {
282+
process.exit(signalToCode(signal));
283+
} else {
284+
process.exit();
285+
}
280286
}
281-
process.on('exit', nxCleanup);
282-
process.on('SIGINT', nxCleanup);
283-
process.on('SIGTERM', nxCleanup);
284-
process.on('SIGHUP', nxCleanup);
287+
288+
process.on('exit', () => {
289+
nxCleanup();
290+
});
291+
process.on('SIGINT', () => {
292+
nxCleanup('SIGINT');
293+
});
294+
process.on('SIGTERM', () => {
295+
nxCleanup('SIGTERM');
296+
});
297+
process.on('SIGHUP', () => {
298+
nxCleanup('SIGHUP');
299+
});
285300

286301
main();

0 commit comments

Comments
 (0)
Please sign in to comment.