Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

monitor: increase buffer to deal with very big messages #1200

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/osbuild/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ type Progress struct {
// NewStatusScanner returns a StatusScanner that can parse osbuild
// jsonseq monitor status messages
func NewStatusScanner(r io.Reader) *StatusScanner {
scanner := bufio.NewScanner(r)
// osbuild can currently generate very long messages, the default
// 64kb is too small for e.g. the dracut stage (see also
// https://github.com/osbuild/osbuild/issues/1976). Increase for
// but to unblock us.
buf := make([]byte, 0, 512_000)
scanner.Buffer(buf, 512_000)
return &StatusScanner{
scanner: bufio.NewScanner(r),
scanner: scanner,
contextMap: make(map[string]*contextJSON),
stageContextMap: make(map[string]*stageContextJSON),
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/osbuild/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package osbuild_test

import (
"bytes"
"fmt"
"os"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -116,3 +118,16 @@ func TestScannerSmoke(t *testing.T) {
assert.NotEqual(t, time.Time{}, st.Timestamp)
}
}

func TestScannerVeryLongLines(t *testing.T) {
buf := bytes.NewBuffer(nil)
fmt.Fprint(buf, `{"message": "`)
fmt.Fprint(buf, strings.Repeat("1", 128_000))
fmt.Fprint(buf, `"}`)

scanner := osbuild.NewStatusScanner(buf)
st, err := scanner.Status()
assert.NoError(t, err)
require.NotNil(t, st)
assert.Equal(t, 128_000, len(st.Trace))
}
Loading