Skip to content

Commit

Permalink
Make stdout maxBuffer length to be configurable
Browse files Browse the repository at this point in the history
The default value is set to 4Gb.

Fixes: #3925

Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
  • Loading branch information
vrubezhny committed Apr 13, 2024
1 parent 1112d45 commit 7570b24
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand Down
9 changes: 8 additions & 1 deletion src/util/childProcessUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CliExitData> {
return new Promise<CliExitData>((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
Expand Down
4 changes: 4 additions & 0 deletions test/unit/util/childProcessUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 7570b24

Please sign in to comment.