Skip to content

fix race binding a named type when loading BSUP projections - #7642

Open
philrz wants to merge 1 commit into
mainfrom
named-projection-race
Open

philrz wants to merge 1 commit into
mainfrom
named-projection-race

Conversation

@philrz

@philrz philrz commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #7641

When a query scans the same BSUP file more than once and the scans project different columns of a named record type, the scans' goroutines race to bind the type's name to their own projected type. The loser panicked with type "foo" redefined. If both got past the check in LookupTypeNamed together, the loser was handed the winner's type for its own vector, so materialized values could come out with the wrong fields (e.g., error("no such field b")).

With this PR, the loader just calls LookupTypeNamed and returns the inner vector if the name is bound to another type, instead of checking LookupByName first. LookupTypeNamed no longer checks for an existing name before calling DeclareTypeNamed, which checks again; it compares the types when DeclareTypeNamed finds the name, as DecodeTypeValue does. The new test fails on main every time, and with only the loader change it fails in 8 of 20 plain runs (all 20 with -race).

On my laptop, a two-branch fork over a one-record file panicked in 13 of 500 runs on main and in 0 of 1000 with the fix. The mgbench bench3 q3 query that first showed it gave identical results in 200 of 200 runs with the fix, and bench3 query times didn't change.

The patch was drafted with Claude Code. I reviewed and tested it, and ran it through Claude Code's /code-review high.

When two scans of the same BSUP file projected different columns of a
named record type, their goroutines raced to bind the type's name.  The
loser panicked with "type redefined", or, if both got past the check in
LookupTypeNamed, was handed the winner's type, so values could come out
with the wrong fields.

The loader now just calls LookupTypeNamed and returns the inner vector
if the name is bound to another type, and LookupTypeNamed compares the
types when DeclareTypeNamed finds the name already declared.

Fixes #7641

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@philrz philrz self-assigned this Nov 11, 2026
@philrz
philrz requested a review from a team November 11, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intermittent panic "type <...> redefined" when a query reads the same BSUP file with a named type more than once

1 participant