From 17fe1ef8657c8ec478e38cc518bea050a97f7cb1 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 7 Feb 2025 12:16:52 +0100 Subject: [PATCH] monitor: increase buffer to deal with very big messages This commit incrases the buffer os the osbuild message scanner to deal with very big messages. The default size of 64kb is too small for the `dracut` stage which will generate 5447 messages that /dev/log is not available and they come so rapidly that osbuild will pick them up in one big chunk. This is a short term fix, the deeper fix should be to tweak the osbuild monitor to have a smaller buffer size when sending stdout/stderr output from stages to the monitor. This will fix a crash in the bootc-image-builder anaconda builds that is currently breaking the integration test in konflux. See also https://github.com/osbuild/osbuild/issues/1976 --- pkg/osbuild/monitor.go | 9 ++++++++- pkg/osbuild/monitor_test.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/osbuild/monitor.go b/pkg/osbuild/monitor.go index 72c8fdb612..c897923da3 100644 --- a/pkg/osbuild/monitor.go +++ b/pkg/osbuild/monitor.go @@ -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), } diff --git a/pkg/osbuild/monitor_test.go b/pkg/osbuild/monitor_test.go index 62a0cba304..fd496da17d 100644 --- a/pkg/osbuild/monitor_test.go +++ b/pkg/osbuild/monitor_test.go @@ -2,7 +2,9 @@ package osbuild_test import ( "bytes" + "fmt" "os" + "strings" "testing" "time" @@ -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)) +}