fix panic in Writer
Commit 766cfece introduced this bug by defining an incorrect split
function. First it breaks the old behavior because it never splits at
newlines now. Second, it causes a panic because it never tells the
scanner to stop. See the bufio.ScanLines function, something like:
```
if atEOF && len(data) == 0 {
return 0, nil, nil
}
```
is needed to do that.
This commit fixes it by restoring the old behavior and calling
bufio.ScanLines but also keep the 64KB check in place to avoid buffering
for to long.
Two tests are added to ensure it is working as expected.
Fixes #1383
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
committed by
Simon Eskildsen
parent
f9291a534c
commit
d40e25cd45
@@ -70,16 +70,16 @@ func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...
|
||||
scanner.Buffer(make([]byte, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize)
|
||||
|
||||
// Define a split function to split the input into chunks of up to 64KB
|
||||
chunkSize := 64 * 1024 // 64KB
|
||||
chunkSize := bufio.MaxScanTokenSize // 64KB
|
||||
splitFunc := func(data []byte, atEOF bool) (int, []byte, error) {
|
||||
if len(data) > chunkSize {
|
||||
if len(data) >= chunkSize {
|
||||
return chunkSize, data[:chunkSize], nil
|
||||
}
|
||||
|
||||
return len(data), data, nil
|
||||
return bufio.ScanLines(data, atEOF)
|
||||
}
|
||||
|
||||
//Use the custom split function to split the input
|
||||
// Use the custom split function to split the input
|
||||
scanner.Split(splitFunc)
|
||||
|
||||
// Scan the input and write it to the logger using the specified print function
|
||||
|
||||
Reference in New Issue
Block a user