Skip to content

[Bug]: objectWriterV1.Write discards the error returned by AddBlock and always reports success #27407

Closed

Description

@loveRhythm1990

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Searched objectWriterV1, objectWriterV1 AddBlock error, AddBlock error ignored — no existing report.

Branch Name

main

Commit ID

c30cd37058

Actual Behavior

objectWriterV1.Write (pkg/objectio/writer.go:316) calls AddBlock and throws away its error, then unconditionally returns nil:

func (w *objectWriterV1) Write(batch *batch.Batch) (BlockObject, error) {
	if col := len(w.seqnums.Seqs); col == 0 {
		w.seqnums.InitWithColCnt(len(batch.Vecs))
	} else if col != len(batch.Vecs) {
		panic(fmt.Sprintf("Unmatched Write Batch, expect %d, get %d, %v", col, len(batch.Vecs), batch.Attrs))
	}
	block := NewBlock(w.seqnums)
	w.AddBlock(block, batch, w.seqnums)     // <-- (int, error) both discarded
	return block, nil                       // <-- always nil
}

AddBlock is declared as func (w *objectWriterV1) AddBlock(blockMeta BlockObject, bat *batch.Batch, seqnums *Seqnums) (int, error) (pkg/objectio/writer.go:832) and can genuinely fail — e.g. marshalling or compression failures in the column loop.

Two consequences:

  1. Callers cannot detect the failure. Every if _, err := writer.Write(bat); err != nil in the codebase is dead code. A block that failed to serialize is reported as written; the error surfaces later, elsewhere, or not at all.
  2. Write also hides its first return value (the number of bytes/rows added), which is discarded here as well.

This was found while investigating a leak in saveMeta (#27405), whose Write error branch is consequently unreachable — which in turn made it harder to reason about which cleanup paths matter.

Introduced in 9b6d192ea3 (#9248, 2023-05-08); AddBlock gained its error return shortly before, in a181a764b7 (#9058, 2023-04-18), so the error has been dropped ever since it existed.

Expected Behavior

Write propagates the error:

block := NewBlock(w.seqnums)
if _, err := w.AddBlock(block, batch, w.seqnums); err != nil {
	return nil, err
}
return block, nil

Worth checking whether other AddBlock call sites drop the error the same way, and whether any caller currently depends on Write never failing.

Steps to Reproduce

  1. Inject a failure inside objectWriterV1.AddBlock (e.g. force WriteWithCompress to fail for one column).
  2. Call objectWriterV1.Write with any batch.
  3. Write returns (block, nil) — the caller sees success despite the block not having been added correctly.

Additional information

Found by source review, not observed as a runtime failure. Filed separately from #27405 / #27406 because it is an independent defect in a different package.

Activity

  1. LeftHandCold commented on Sep 1, 2026

    @LeftHandCold
    Collaborator

    Current-main root-cause verification (2026-09-01)

    Classification: proven at the reported SHA, but already resolved on current
    main; this overlaps the earlier #26870.

    At the issue's exact baseline c30cd3705855a61333519dc7a27693c0b4443d92,
    a malformed text vector makes AddBlock return
    vector data is shorter than its marshal length. A deterministic test confirms
    that both Write and WriteWithoutSeqnum nevertheless returned a non-nil
    block and nil error. The root cause was exactly the unchecked call followed by
    an unconditional return block, nil.

    The production fix already landed in #26616 at
    ed4a810a539d8b7feae95711d37e7d7d9449d89f: both active wrappers now return
    nil, err. Current main
    33af6ae3c0c23e4f277137460577ea64678f7ecf passes the same counterexample and
    the full pkg/objectio package tests.

    PR #27949 is a narrow regression follow-up: it keeps the existing Write
    coverage and adds the missing WriteWithoutSeqnum subcase. No additional
    production-code patch is appropriate because the implementation is already
    correct on main.

    Impact remains conditional: the defect silently hid a real serialization error,
    but the available evidence does not establish a naturally occurring valid-SQL
    input or observed production data loss.

  2. LeftHandCold commented on Sep 1, 2026

    @LeftHandCold
    Collaborator

    fixed

  3. LeftHandCold commented on Sep 1, 2026

    @LeftHandCold
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions