From 4398f660ba480c82eb31526d7ed7413f80667249 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Sun, 20 Aug 2023 18:03:45 +0200 Subject: [PATCH 1/2] fix: execute the Arduino CLI without a `shell` Closes arduino/arduino-ide#2112 Ref: arduino/arduino-ide#2067 Signed-off-by: Akos Kitta --- arduino-ide-extension/src/node/arduino-daemon-impl.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arduino-ide-extension/src/node/arduino-daemon-impl.ts b/arduino-ide-extension/src/node/arduino-daemon-impl.ts index d2fe7d81b..b7af78627 100644 --- a/arduino-ide-extension/src/node/arduino-daemon-impl.ts +++ b/arduino-ide-extension/src/node/arduino-daemon-impl.ts @@ -173,10 +173,9 @@ export class ArduinoDaemonImpl const cliPath = this.getExecPath(); const ready = new Deferred<{ daemon: ChildProcess; port: string }>(); const options = { - shell: true, env: { ...deepClone(process.env), NO_COLOR: String(true) }, }; - const daemon = spawn(`"${cliPath}"`, args, options); + const daemon = spawn(cliPath, args, options); // If the process exists right after the daemon gRPC server has started (due to an invalid port, unknown address, TCP port in use, etc.) // we have no idea about the root cause unless we sniff into the first data package and dispatch the logic on that. Note, we get a exit code 1. From b50f0f8d3070359ef81f2847bafb609d4a4ac067 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Sun, 20 Aug 2023 18:09:48 +0200 Subject: [PATCH 2/2] fix: do not start obsolete daemon watcher process Before arduino/arduino-cli#488, IDE2 required a way to stop the daemon process if the parent (backend) process crashed. However, this mechanism is no longer necessary as the CLI daemon process is not actually a true daemon process. Signed-off-by: Akos Kitta --- .../src/node/arduino-daemon-impl.ts | 17 -------------- .../src/node/daemon-watcher.ts | 22 ------------------- 2 files changed, 39 deletions(-) delete mode 100644 arduino-ide-extension/src/node/daemon-watcher.ts diff --git a/arduino-ide-extension/src/node/arduino-daemon-impl.ts b/arduino-ide-extension/src/node/arduino-daemon-impl.ts index b7af78627..16db90631 100644 --- a/arduino-ide-extension/src/node/arduino-daemon-impl.ts +++ b/arduino-ide-extension/src/node/arduino-daemon-impl.ts @@ -10,7 +10,6 @@ import { } from '@theia/core/lib/common/disposable'; import { Event, Emitter } from '@theia/core/lib/common/event'; import { deepClone } from '@theia/core/lib/common/objects'; -import { environment } from '@theia/application-package/lib/environment'; import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application'; import { ArduinoDaemon, NotificationServiceServer } from '../common/protocol'; @@ -71,22 +70,6 @@ export class ArduinoDaemonImpl const cliPath = this.getExecPath(); this.onData(`Starting daemon from ${cliPath}...`); const { daemon, port } = await this.spawnDaemonProcess(); - // Watchdog process for terminating the daemon process when the backend app terminates. - spawn( - process.execPath, - [ - join(__dirname, 'daemon-watcher.js'), - String(process.pid), - String(daemon.pid), - ], - { - env: environment.electron.runAsNodeEnv(), - detached: true, - stdio: 'ignore', - windowsHide: true, - } - ).unref(); - this.toDispose.pushAll([ Disposable.create(() => { if (daemon.pid) { diff --git a/arduino-ide-extension/src/node/daemon-watcher.ts b/arduino-ide-extension/src/node/daemon-watcher.ts deleted file mode 100644 index 842a4e2f2..000000000 --- a/arduino-ide-extension/src/node/daemon-watcher.ts +++ /dev/null @@ -1,22 +0,0 @@ -import psTree from 'ps-tree'; -import kill from 'tree-kill'; -const [theiaPid, daemonPid] = process.argv - .slice(2) - .map((id) => Number.parseInt(id, 10)); - -setInterval(() => { - try { - // Throws an exception if the Theia process doesn't exist anymore. - process.kill(theiaPid, 0); - } catch { - psTree(daemonPid, function (_, children) { - for (const { PID } of children) { - const parsedPid = Number.parseInt(PID, 10); - if (!Number.isNaN(parsedPid)) { - kill(parsedPid); - } - } - kill(daemonPid, () => process.exit()); - }); - } -}, 1000);