Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): prevent cmd popups from isolation #26730

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 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, Serializable, fork } from 'child_process';
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 @@ -248,15 +249,17 @@ function createWorkerExitHandler(

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

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

function registerPendingPromise(
Expand Down Expand Up @@ -314,17 +317,21 @@ async function startPluginWorker() {
[process.pid, global.nxPluginWorkerCount++].join('-')
);

const worker = fork(workerPath, [ipcPath], {
stdio: process.stdout.isTTY ? 'inherit' : 'ignore',
env,
execArgv: [
...process.execArgv,
// If the worker is typescript, we need to register ts-node
...(isWorkerTypescript ? ['-r', 'ts-node/register'] : []),
const worker = spawn(
process.execPath,
[
...(isWorkerTypescript ? ['--require', 'ts-node/register'] : []),
workerPath,
ipcPath,
],
detached: true,
});
worker.disconnect();
{
stdio: process.stdout.isTTY ? 'inherit' : 'ignore',
env,
detached: true,
shell: false,
windowsHide: true,
}
);
worker.unref();

let attempts = 0;
Expand Down