fix(sandbox): use spawnSync in exit handler to avoid resource leaks

This commit is contained in:
Spencer
2026-02-27 21:34:18 +00:00
parent 5b08f0644d
commit f4e7d4159a
2 changed files with 13 additions and 6 deletions
+2
View File
@@ -70,6 +70,8 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
}, },
spawnAsync: mockSpawnAsync, spawnAsync: mockSpawnAsync,
LOCAL_DEV_SANDBOX_IMAGE_NAME: 'gemini-cli-sandbox', LOCAL_DEV_SANDBOX_IMAGE_NAME: 'gemini-cli-sandbox',
SANDBOX_NETWORK_NAME: 'gemini-cli-sandbox',
SANDBOX_PROXY_NAME: 'gemini-cli-sandbox-proxy',
homedir: mockedHomedir, homedir: mockedHomedir,
}; };
}); });
+11 -6
View File
@@ -4,7 +4,12 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { execSync, spawn, type ChildProcess } from 'node:child_process'; import {
execSync,
spawn,
spawnSync,
type ChildProcess,
} from 'node:child_process';
import path from 'node:path'; import path from 'node:path';
import fs from 'node:fs'; import fs from 'node:fs';
import os from 'node:os'; import os from 'node:os';
@@ -688,11 +693,11 @@ export async function start_sandbox(
// install handlers to stop proxy on exit/signal // install handlers to stop proxy on exit/signal
const stopProxy = () => { const stopProxy = () => {
debugLogger.log('stopping proxy container ...'); debugLogger.log('stopping proxy container ...');
return spawnAsync(config.command, [ try {
'rm', spawnSync(config.command, ['rm', '-f', SANDBOX_PROXY_NAME]);
'-f', } catch {
SANDBOX_PROXY_NAME, // ignore
])?.catch(() => {}); }
}; };
process.off('exit', stopProxy); process.off('exit', stopProxy);