Skip to content

Commit

Permalink
monitor: increase buffer to deal with very big messages
Browse files Browse the repository at this point in the history
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 osbuild/osbuild#1976
  • Loading branch information
mvo5 committed Feb 7, 2025
1 parent 6191f47 commit 17fe1ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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))
}

0 comments on commit 17fe1ef

Please sign in to comment.