mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-17 00:31:44 -07:00
fix(core): remove buffer slice to prevent OOM on large output streams (#25094)
This commit is contained in:
@@ -1610,6 +1610,22 @@ describe('ShellExecutionService child_process fallback', () => {
|
||||
'exit',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should correctly measure sniffedBytes with >20 small chunks to prevent OOM (regression #22170)', async () => {
|
||||
mockIsBinary.mockReturnValue(false);
|
||||
|
||||
await simulateExecution('cat lots_of_chunks', (cp) => {
|
||||
for (let i = 0; i < 25; i++) {
|
||||
cp.stdout?.emit('data', Buffer.alloc(10, 'a'));
|
||||
}
|
||||
cp.emit('exit', 0, null);
|
||||
cp.emit('close', 0, null);
|
||||
});
|
||||
|
||||
const lastCallBuffer =
|
||||
mockIsBinary.mock.calls[mockIsBinary.mock.calls.length - 1][0];
|
||||
expect(lastCallBuffer.length).toBe(250);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Platform-Specific Behavior', () => {
|
||||
|
||||
@@ -630,7 +630,7 @@ export class ShellExecutionService {
|
||||
}
|
||||
|
||||
if (isStreamingRawContent && sniffedBytes < MAX_SNIFF_SIZE) {
|
||||
const sniffBuffer = Buffer.concat(state.sniffChunks.slice(0, 20));
|
||||
const sniffBuffer = Buffer.concat(state.sniffChunks);
|
||||
sniffedBytes = sniffBuffer.length;
|
||||
|
||||
if (isBinary(sniffBuffer)) {
|
||||
@@ -1094,7 +1094,7 @@ export class ShellExecutionService {
|
||||
}
|
||||
|
||||
if (isStreamingRawContent && sniffedBytes < MAX_SNIFF_SIZE) {
|
||||
const sniffBuffer = Buffer.concat(sniffChunks.slice(0, 20));
|
||||
const sniffBuffer = Buffer.concat(sniffChunks);
|
||||
sniffedBytes = sniffBuffer.length;
|
||||
|
||||
if (isBinary(sniffBuffer)) {
|
||||
|
||||
Reference in New Issue
Block a user