Skip to content

Commit

Permalink
fix(core): exit on sigint
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Jun 27, 2024
1 parent 13e795a commit 17d6f3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NX_ISOLATE_PLUGINS=true
# NX_ISOLATE_PLUGINS=true
16 changes: 10 additions & 6 deletions packages/nx/src/project-graph/plugins/isolation/plugin-pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChildProcess, spawn } from 'child_process';
import path = require('path');
import { Socket, connect } from 'net';

import { PluginConfiguration } from '../../../config/nx-json';

Expand All @@ -9,13 +10,13 @@ import { PluginConfiguration } from '../../../config/nx-json';
import { LoadedNxPlugin, nxPluginCache } from '../internal-api';
import { getPluginOsSocketPath } from '../../../daemon/socket-utils';
import { consumeMessagesFromSocket } from '../../../utils/consume-messages-from-socket';
import { signalToCode } from '../../../utils/exit-codes';

import {
consumeMessage,
isPluginWorkerResult,
sendMessageOverSocket,
} from './messaging';
import { Socket, connect } from 'net';

const cleanupFunctions = new Set<() => void>();

Expand Down Expand Up @@ -247,17 +248,20 @@ function createWorkerExitHandler(
}

let cleanedUp = false;
const exitHandler = () => {
if (cleanedUp) return;
const exitHandler = (code) => () => {
if (cleanedUp) {
process.exit(code);
}
for (const fn of cleanupFunctions) {
fn();
}
cleanedUp = true;
process.exit(code);
};

process.on('exit', exitHandler);
process.on('SIGINT', exitHandler);
process.on('SIGTERM', exitHandler);
process.on('exit', (code) => exitHandler(code)());
process.on('SIGINT', exitHandler(signalToCode('SIGINT')));
process.on('SIGTERM', exitHandler(signalToCode('SIGTERM')));

function registerPendingPromise(
tx: string,
Expand Down

0 comments on commit 17d6f3b

Please sign in to comment.