Skip to content

Commit 0271eee

Browse files
committed
Handle large log rows
1 parent 82a5ab0 commit 0271eee

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

agent/server/snykbroker/supervisor.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,29 @@ func (b *Supervisor) scanLines(reader io.Reader, output chan string, refCount *s
252252
done := false
253253

254254
refCount.Add(1)
255+
256+
// increase buffer size from default of 60K to 1MB
257+
buffer := make([]byte, 1024*1024)
255258
go func() {
256-
scanner := bufio.NewScanner(reader)
257-
for scanner.Scan() {
258-
ln := scanner.Text()
259-
output <- ln
260-
if done {
261-
break
259+
for {
260+
scanner := bufio.NewScanner(reader)
261+
scanner.Buffer(buffer, cap(buffer)-1)
262+
for scanner.Scan() {
263+
ln := scanner.Text()
264+
output <- ln
265+
if done {
266+
return
267+
}
262268
}
263-
}
264-
err := scanner.Err()
265-
if err != nil {
266-
output <- fmt.Sprintf("Error reading from scanner: %v", err)
269+
err := scanner.Err()
270+
if err != nil {
271+
output <- fmt.Sprintf("Warning (non-fatal), failed to read from scanner to pipe output: %v", err)
272+
}
273+
274+
// dump what we have in the buffer, then continue
275+
output <- string(buffer) + "...[END OF BUFFER]"
267276
}
268277

269-
b, _ := io.ReadAll(reader)
270-
output <- string(b)
271278
}()
272279

273280
return func() {

0 commit comments

Comments
 (0)