Repository navigation
Description
Is there an existing issue for the same bug?
- I have searched. This is the missing size bound on the JSONLINE holdover buffer, already tracked as part of [Bug]: JSONLINE truncated-record holdover aliases a reused parser buffer, so record continuation never works #31280 ("JSONLINE truncated-record holdover...", consolidated there from [Bug]: JSONLINE truncated-record holdover grows prevStr past LargestEntryLimit with no size bound #31304/[Bug]: JSONLINE truncation holdover re-parses the whole prefix every line and grows past LargestEntryLimit #31851 on 2026-10-31). This report re-verifies that the defect is still present on a newer main commit (8ff3c0d, 2026-11-02, three days after the consolidation) and adds two new measurements the tracker does not have: the batch byte-budget bypass, and the total-allocation amplification of a full strict scan. No open PR touches this path.
Branch Name
main
Commit ID
Other Environment Information
- Hardware parameters: Apple Silicon (arm64, macOS); Go unit test only, no server needed
- OS type: darwin/arm64, go1.27.1
- Others: workspace build of main; test reuses the committed helpers
errorModeParam/colLinefrompkg/sql/colexec/external/error_mode_test.go
Actual Behavior
A strict-mode JSONLINE scan of a file whose first record opens a string value it never closes is classified as truncated on every following physical line. CsvReader.prevStr (pkg/sql/colexec/external/reader_csv.go) then concatenates each new line onto the whole tail:
transJsonObject2Lines(:320-322):str = r.prevStr + str— never measured. When the parse reportsunexpected EOFand the text still opens an object (jsonLineTruncated, :267-273), the entire accumulated text is stored back as the new holdover (:327-329).transJsonArray2Lineshas the same pattern (:388-390, :394-396).- The caller
makeBatchRowstreats a truncated record as "held over for the next line" and doescontinue(:213-214) — which skips the batch budget check at :252 (curBatchSize >= param.maxBatchSize), so a run of continuation lines never hands the batch on. - Each line alone obeys the CSV parser's per-record cap
config.LargestEntryLimit(64 MiB, pkg/config/configuration.go:213,largest-entry-limit), but the assembled holdover record has no cap of any kind, and the whole growing buffer is re-allocated and re-scanned on every new line (O(file^2)). - The scan only fails at EOF with
invalid input: incomplete json record(:165-171), after the whole remaining file has been absorbed.
Measured on the commit above (default LargestEntryLimit = 67108864, fixture maxBatchSize = 1048576):
- White-box: an opening
{"a":1,"s":"continued with 2 MiBx-only lines growsprevStrto 67,108,876 bytes — already past the 64 MiB record cap — with no error, and it keeps growing line after line. - End-to-end: a 9,830,562-byte truncated file (150 pad lines) is scanned by ONE
makeBatchRowsin 0.09s while allocating 746,696,376 bytes (76x the file size) before finally failing withincomplete json record. Nothing loads.
A corrupted or partially uploaded JSONLINE file therefore makes the CN buffer the remainder of the file in one Go-heap string (invisible to mpool accounting and to largest-entry-limit) and burn quadratic parse CPU — the class of load memory-exhaustion the per-record cap exists to prevent.
Expected Behavior
The hold-over record is one row of the load. A single physical line larger than config.LargestEntryLimit is already rejected by the CSV parser precisely so one record cannot exhaust parse memory; the same cap must apply to the assembled record: once the concatenation at reader_csv.go:321 (and :389) would grow past config.LargestEntryLimit, the reader must fail the record immediately with an invalid-input error instead of holding and re-parsing it. The truncated-line continuation must also not bypass the batch byte budget (curBatchSize >= param.maxBatchSize).
Steps to Reproduce
Save the test below as pkg/sql/colexec/external/loom_jsonline_prevstr_growth_test.go and run from the repo root (helpers errorModeParam/colLine/newCSVParserFromReader are committed in the package):
CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include" \
go test ./pkg/sql/colexec/external -run TestLoomJSONLineTruncated -count=1 -vBoth TestLoomJSONLineTruncatedPrevStrGrowsUncapped and TestLoomJSONLineTruncatedScanBuffersWholeFile fail on main (kept failing across repeated runs, deterministic).
// Copyright 2026 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package external
import (
"io"
"runtime"
"strings"
"testing"
"github.com/matrixorigin/matrixone/pkg/config"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/stretchr/testify/require"
)
// A JSONLINE object whose string value is never closed is classified as
// "truncated" on every physical line that continues it, so strict-mode
// scanning (reader_csv.go) holds the whole tail over in CsvReader.prevStr and
// re-copies/re-parses it on each following line. The CSV parser caps a single
// record at config.LargestEntryLimit, but this hold-over record is assembled
// outside the parser and has no cap at all: a corrupted or truncated JSONLINE
// file makes the scan buffer the whole remaining file and spend O(file^2)
// work before failing at EOF.
// Expected: a held-over JSONLINE record must obey the load parser's per-record
// cap (config.LargestEntryLimit, `largest-entry-limit` in the CN toml), just
// like any record the CSV parser reads directly.
func TestLoomJSONLineTruncatedPrevStrGrowsUncapped(t *testing.T) {
param, proc, _ := errorModeParam(t, tree.JSONLINE, tree.OBJECT, colLine)
require.False(t, param.ErrorMode.Tolerate, "strict scan for declared columns only")
ctx := proc.Ctx
r := &CsvReader{param: param}
first := `{"a":1,"s":"`
_, err := r.transJsonObject2Lines(ctx, first, param.Attrs, param.Cols)
require.Error(t, err)
require.True(t, jsonLineTruncated(err, first, '{'),
"unterminated string must be classified as truncated, got %v", err)
require.Equal(t, first, r.prevStr)
// Continue the record with 2 MiB physical lines, the same way
// makeBatchRows drives it (transJson2Lines error -> truncated -> continue).
chunk := strings.Repeat("x", 2<<20)
for i := 0; len(r.prevStr) <= int(config.LargestEntryLimit); i++ {
require.Less(t, i, 64, "did not expect the record to grow so long")
_, err := r.transJsonObject2Lines(ctx, chunk, param.Attrs, param.Cols)
require.Error(t, err)
}
t.Logf("held-over record after %d continuation lines: %d bytes (record cap %d, batch budget %d)",
int(len(r.prevStr)/(2<<20)), len(r.prevStr), config.LargestEntryLimit, param.maxBatchSize)
require.LessOrEqual(t, len(r.prevStr), int(config.LargestEntryLimit),
"the held-over JSONLINE record must be capped by largest-entry-limit like every other record")
}
// Expected: a strict scan of a truncated JSONLINE file must not buffer the
// whole file and re-copy it once per line before failing at EOF.
func TestLoomJSONLineTruncatedScanBuffersWholeFile(t *testing.T) {
param, proc, bat := errorModeParam(t, tree.JSONLINE, tree.OBJECT, colLine)
var content strings.Builder
content.WriteString(`{"a":1,"s":"`)
pad := strings.Repeat("x", 64<<10) // 64 KiB continuation lines
const padLines = 150
for i := 0; i < padLines; i++ {
content.WriteByte('\n')
content.WriteString(pad)
}
fileSize := content.Len()
r := &CsvReader{param: param}
r.reader = io.NopCloser(strings.NewReader(content.String()))
parser, err := newCSVParserFromReader(param.Extern, r.reader)
require.NoError(t, err)
r.plh = &ParseLineHandler{csvReader: parser}
var before, after runtime.MemStats
runtime.GC()
runtime.ReadMemStats(&before)
_, err = r.makeBatchRows(proc, bat)
runtime.ReadMemStats(&after)
require.Error(t, err)
require.Contains(t, err.Error(), "incomplete json record")
allocated := after.TotalAlloc - before.TotalAlloc
t.Logf("%d-byte truncated file (%d pad lines) scanned: %d bytes allocated before failing",
fileSize, padLines, allocated)
require.LessOrEqual(t, allocated, uint64(10*fileSize),
"scanning a truncated record must not copy the held tail once per line")
}
// One short truncated record still fails cleanly at EOF, for contrast.
func TestLoomJSONLineTruncatedRecordEOFStillFails(t *testing.T) {
param, proc, _ := errorModeParam(t, tree.JSONLINE, tree.OBJECT, colLine)
r := &CsvReader{param: param}
_, err := r.transJsonObject2Lines(proc.Ctx, `{"a":1,"s":"x`, param.Attrs, param.Cols)
require.Error(t, err)
require.True(t, jsonLineTruncated(err, r.prevStr, '{'))
require.LessOrEqual(t, len(r.prevStr), int(config.LargestEntryLimit))
}Additional information
- Root cause locations:
pkg/sql/colexec/external/reader_csv.go:214— the truncated continuationcontinueskips the batch-size check at :252;pkg/sql/colexec/external/reader_csv.go:321and:328— the unboundedprevStrconcatenation and holdback (array variant :389/:396). - Suggested fix: after concatenating at :321 (and :389), if
len(str) > config.LargestEntryLimitreturn a non-truncated invalid-input error (and do not store it intoprevStr), mirroring the single-line cap; also make the truncated continuation honor the batch budget. No existing data is affected: strict scans fail at EOF today anyway, this only fails them earlier and bounded. - The Kafka entry point is not affected:
parseOneMessageclearsprevStron every error (pkg/sql/colexec/external/reader_kafka.go:398). - Relation to the tracked issue: [Bug]: JSONLINE truncated-record holdover aliases a reused parser buffer, so record continuation never works #31280's heading focuses on holdover correctness (buffer aliasing); this resource-bound aspect is tracked in the same consolidated issue (see [Bug]: JSONLINE truncated-record holdover grows prevStr past LargestEntryLimit with no size bound #31304/[Bug]: JSONLINE truncation holdover re-parses the whole prefix every line and grows past LargestEntryLimit #31851 closed-as-duplicate). It remains unfixed at 8ff3c0d, verified by the failing tests above.
Full reproduction, exactly as Loom ran it
Save as pkg/sql/colexec/external/loom_jsonline_prevstr_growth_test.go (helpers errorModeParam/colLine/newCSVParserFromReader are committed in the package), then run from the repo root:
CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include" go test ./pkg/sql/colexec/external -run TestLoomJSONLineTruncated -count=1 -v
Both TestLoomJSONLineTruncatedPrevStrGrowsUncapped and TestLoomJSONLineTruncatedScanBuffersWholeFile fail on main at 8ff3c0d81da; the contrast subtest TestLoomJSONLineTruncatedRecordEOFStillFails passes.
// Copyright 2026 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package external
import (
"io"
"runtime"
"strings"
"testing"
"github.com/matrixorigin/matrixone/pkg/config"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/stretchr/testify/require"
)
func TestLoomJSONLineTruncatedPrevStrGrowsUncapped(t *testing.T) {
param, proc, _ := errorModeParam(t, tree.JSONLINE, tree.OBJECT, colLine)
require.False(t, param.ErrorMode.Tolerate, "strict scan for declared columns only")
ctx := proc.Ctx
r := &CsvReader{param: param}
first := `{"a":1,"s":"`
_, err := r.transJsonObject2Lines(ctx, first, param.Attrs, param.Cols)
require.Error(t, err)
require.True(t, jsonLineTruncated(err, first, '{'), "unterminated string must be classified as truncated, got %v", err)
require.Equal(t, first, r.prevStr)
chunk := strings.Repeat("x", 2<<20)
for i := 0; len(r.prevStr) <= int(config.LargestEntryLimit); i++ {
require.Less(t, i, 64, "did not expect the record to grow so long")
_, err := r.transJsonObject2Lines(ctx, chunk, param.Attrs, param.Cols)
require.Error(t, err)
}
t.Logf("held-over record after %d continuation lines: %d bytes (record cap %d, batch budget %d)", int(len(r.prevStr)/(2<<20)), len(r.prevStr), config.LargestEntryLimit, param.maxBatchSize)
require.LessOrEqual(t, len(r.prevStr), int(config.LargestEntryLimit), "the held-over JSONLINE record must be capped by largest-entry-limit like every other record")
}
func TestLoomJSONLineTruncatedScanBuffersWholeFile(t *testing.T) {
param, proc, bat := errorModeParam(t, tree.JSONLINE, tree.OBJECT, colLine)
var content strings.Builder
content.WriteString(`{"a":1,"s":"`)
pad := strings.Repeat("x", 64<<10)
const padLines = 150
for i := 0; i < padLines; i++ {
content.WriteByte('\n')
content.WriteString(pad)
}
fileSize := content.Len()
r := &CsvReader{param: param}
r.reader = io.NopCloser(strings.NewReader(content.String()))
parser, err := newCSVParserFromReader(param.Extern, r.reader)
require.NoError(t, err)
r.plh = &ParseLineHandler{csvReader: parser}
var before, after runtime.MemStats
runtime.GC()
runtime.ReadMemStats(&before)
_, err = r.makeBatchRows(proc, bat)
runtime.ReadMemStats(&after)
require.Error(t, err)
require.Contains(t, err.Error(), "incomplete json record")
allocated := after.TotalAlloc - before.TotalAlloc
t.Logf("%d-byte truncated file (%d pad lines) scanned: %d bytes allocated before failing", fileSize, padLines, allocated)
require.LessOrEqual(t, allocated, uint64(10*fileSize), "scanning a truncated record must not copy the held tail once per line")
}
func TestLoomJSONLineTruncatedRecordEOFStillFails(t *testing.T) {
param, proc, _ := errorModeParam(t, tree.JSONLINE, tree.OBJECT, colLine)
r := &CsvReader{param: param}
_, err := r.transJsonObject2Lines(proc.Ctx, `{"a":1,"s":"x`, param.Attrs, param.Cols)
require.Error(t, err)
require.True(t, jsonLineTruncated(err, r.prevStr, '{'))
require.LessOrEqual(t, len(r.prevStr), int(config.LargestEntryLimit))
}Found by Loom bug hunt (module: custom-de41a00730; tests: unit, white-box, end-to-end, concurrency; severity: S1)
Activity
Bound JSONLINE continuation and respect batch budget (#32366)
slyunnn commentedon Nov 17, 2026
Regression and extended verification for #32055 (2026-11-17)
Verification Environment
MatrixOne
origin/maincommite765c5fd44e842167d4271c37af6d25586511e16—fix: correct temporal numeric coercion for bit consumers (#32642)— freshly built and confirmed viagit_version()on Proxy6001, CN116001, CN216002. Native2 CN / 1 TN / 1 Log service / Proxy. MySQL text protocol via PyMySQL; checks were serial.What Was Covered
68,157,518-byte input exceeded the default67,108,864-byte record limit through Proxy. The server returned20301with the cumulative-record limit error, committed0rows and subsequently answeredSELECT 1.0rows; a valid object file loaded2rows. These controls ran separately through Proxy, CN1 and CN2.65 MiBboundary test was executed through Proxy only; production-scale concurrency, RSS/GC and full SQL throughput were not measured.4.2-devand released-server compatibility were not tested.Findings
PR #32366, commit
374ad5847f5ca2c57e355487bb375380bd8b57e3—Bound JSONLINE continuation and respect batch budget— is included in the verified main commit. The default-size boundary requires a multi-line file slightly above64 MiB; this focused local boundary test used the minimum relevant scale, with no production-scale performance claim. Existing product reader tests and JSONLINE BVT cover the same contract, so no redundant MOTR case was added.MOTR / BVT Coverage
Existing product tests:
pkg/sql/colexec/external/jsonline_pending_test.goandjsonline_qa_test.go; existing SQL regression:test/distributed/cases/load_data/issue_29842_jsonline_strict_eof.sql. This run executed the focused Go tests and direct SQL fixtures; it did not rerun the complete BVT group or a Nightly workflow.Final Conclusion
Fixed on the verified
maincommit for the reported cumulative JSONLINE record limit and budget handling.