From 7570b24dccb1ff307f6d18d96a30e202b73330a6 Mon Sep 17 00:00:00 2001 From: Victor Rubezhny Date: Sat, 13 Apr 2024 01:19:31 +0200 Subject: [PATCH] Make stdout maxBuffer length to be configurable The default value is set to 4Gb. Fixes: #3925 Signed-off-by: Victor Rubezhny --- package.json | 5 +++++ src/util/childProcessUtil.ts | 9 ++++++++- test/unit/util/childProcessUtil.test.ts | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index fd7c3cffb..c2a3c71a0 100644 --- a/package.json +++ b/package.json @@ -2238,6 +2238,11 @@ "type": "number", "default": 90000, "description": "Controls stopping development mode timeout (in milliseconds)." + }, + "openshiftToolkit.execMaxBufferLength": { + "type": "number", + "default": 4, + "description": "MiB of memory to allocate for stdout buffer when executing a binary" } } }, diff --git a/src/util/childProcessUtil.ts b/src/util/childProcessUtil.ts index 8695ae317..8df968a44 100644 --- a/src/util/childProcessUtil.ts +++ b/src/util/childProcessUtil.ts @@ -78,10 +78,17 @@ export class ChildProcessUtil { this.odoChannel = odoChannel; } + public static getExecMaxBufferLength(): number { + const execMaxBufferLengthFromSetting: string = vscode.workspace.getConfiguration('openshiftToolkit') + .get('execMaxBufferLength'); + const length = parseInt(execMaxBufferLengthFromSetting, 10); + return (!isNaN(length) && length > 0 ? length : 4) * 1024 * 1024; + } + public execute(cmd: string, opts: cp.ExecOptions = {}): Promise { return new Promise((resolve) => { if (opts.maxBuffer === undefined) { - opts.maxBuffer = 2 * 1024 * 1024; + opts.maxBuffer = ChildProcessUtil.getExecMaxBufferLength(); } cp.exec(cmd, opts, (error: cp.ExecException, stdout: string, stderr: string) => { // filter out info about update diff --git a/test/unit/util/childProcessUtil.test.ts b/test/unit/util/childProcessUtil.test.ts index 8dbb28ef5..fe5d08bb5 100644 --- a/test/unit/util/childProcessUtil.test.ts +++ b/test/unit/util/childProcessUtil.test.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See LICENSE file in the project root for license information. *-----------------------------------------------------------------------------------------------*/ +import * as vscode from 'vscode'; import * as chai from 'chai'; import * as childProcess from 'child_process'; import * as sinon from 'sinon'; @@ -43,6 +44,9 @@ suite('ChildProcessUtil', function() { }); test('execute uses a 2MB buffer by default', async function() { + // Change Exec Max Buffer Length to 2Mb (while the default value is 4Gb) + await vscode.workspace.getConfiguration('openshiftToolkit').update('execMaxBufferLength', 2); + execStub.yields(null, stdout, ''); await childProcessUtil.execute(command);