mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 21:03:05 -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,
|
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,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user