From 22fae9344dba36ff3b02387c571e5890381595f0 Mon Sep 17 00:00:00 2001 From: "Geoffrey C. Begen" Date: Wed, 16 Feb 2022 14:24:39 -0800 Subject: [PATCH] Allow long lines in output of daemon and prep commands. The default bufio.Reader buffer size of 4K is too small in some contexts. Use a buffer size of 64K instead. --- shell/shell.go | 4 +++- shell/shell_test.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/shell/shell.go b/shell/shell.go index c0b6aec..f9781e6 100644 --- a/shell/shell.go +++ b/shell/shell.go @@ -23,6 +23,8 @@ var shellTesting bool var Default = "modd" +const maxLineLen = 64 * 1024 + type Executor struct { Shell string Command string @@ -162,7 +164,7 @@ func (e *Executor) Stop() error { func logOutput(wg *sync.WaitGroup, fp io.ReadCloser, out func(string, ...interface{})) { defer wg.Done() - r := bufio.NewReader(fp) + r := bufio.NewReaderSize(fp, maxLineLen) for { line, _, err := r.ReadLine() if err != nil { diff --git a/shell/shell_test.go b/shell/shell_test.go index 34ce388..711965e 100644 --- a/shell/shell_test.go +++ b/shell/shell_test.go @@ -90,6 +90,16 @@ func testCmd(t *testing.T, shell string, ct cmdTest) { } } +var longLine = func() string { + // 6K is longer than the default buffer size, but still well under the + // powershell command line length limit of 8191 + var runes [6 * 1024]rune + for i := range runes { + runes[i] = rune('0' + i%10) + } + return string(runes[:]) +}() + var shellTests = []cmdTest{ { name: "echosuccess", @@ -129,6 +139,11 @@ var shellTests = []cmdTest{ kill: true, procerr: true, }, + { + name: "longline", + cmd: "echo " + longLine + "; true", + logHas: longLine, + }, } func TestShells(t *testing.T) {