From 13e5691dcde5f7c29c144d1cb8c34f453d78505d Mon Sep 17 00:00:00 2001 From: Caleb Spare Date: Fri, 27 Aug 2021 14:13:14 -0700 Subject: [PATCH] Handle output lines longer than 64 KiB This raises the limit to 100 MB. We buffer them in memory so we don't want to make it unlimited. Fixes #83. --- reflex.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/reflex.go b/reflex.go index f04aa88..528cca5 100644 --- a/reflex.go +++ b/reflex.go @@ -287,10 +287,15 @@ func (r *Reflex) runCommand(name string, stdout chan<- OutMsg) { go func() { scanner := bufio.NewScanner(tty) + // Allow for lines up to 100 MB. + scanner.Buffer(nil, 100e6) for scanner.Scan() { stdout <- OutMsg{r.id, scanner.Text()} } - // Intentionally ignoring scanner.Err() for now. Unfortunately, + if err := scanner.Err(); errors.Is(err, bufio.ErrTooLong) { + infoPrintln(r.id, "Error: subprocess emitted a line longer than 100 MB") + } + // Intentionally ignore other scanner errors. Unfortunately, // the pty returns a read error when the child dies naturally, // so I'm just going to ignore errors here unless I can find a // better way to handle it.