mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-22 12:01:39 -07:00
fix(sandbox): use spawnSync in exit handler to avoid resource leaks
This commit is contained in:
@@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user