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

View File

@@ -70,6 +70,8 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
},
spawnAsync: mockSpawnAsync,
LOCAL_DEV_SANDBOX_IMAGE_NAME: 'gemini-cli-sandbox',
SANDBOX_NETWORK_NAME: 'gemini-cli-sandbox',
SANDBOX_PROXY_NAME: 'gemini-cli-sandbox-proxy',
homedir: mockedHomedir,
};
});

View File

@@ -4,7 +4,12 @@
* 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 fs from 'node:fs';
import os from 'node:os';
@@ -688,11 +693,11 @@ export async function start_sandbox(
// install handlers to stop proxy on exit/signal
const stopProxy = () => {
debugLogger.log('stopping proxy container ...');
return spawnAsync(config.command, [
'rm',
'-f',
SANDBOX_PROXY_NAME,
])?.catch(() => {});
try {
spawnSync(config.command, ['rm', '-f', SANDBOX_PROXY_NAME]);
} catch {
// ignore
}
};
process.off('exit', stopProxy);