Skip to content

fix: guard primitive graph txn control counter slice against concurrent appends - #736

Merged
jeffreyaven merged 1 commit into
mainfrom
fix/txn-counter-slice-race
Sep 6, 2026
Merged

jeffreyaven merged 1 commit into
mainfrom
fix/txn-counter-slice-race

Conversation

@jeffreyaven

Copy link
Copy Markdown
Member

Description

standardBasePrimitiveGraph.AddTxnControlCounters appended to txnControlCounterSlice with no synchronisation, but it is called from executor closures that run inside the graph's errgroup. With an unbounded concurrency limit the arms of a UNION ALL execute in parallel and append at the same time; the torn slice header surfaces as a nil pointer panic:

panic: runtime error: invalid memory address or nil pointer dereference
github.com/stackql/stackql/internal/stackql/primitivegraph.(*standardBasePrimitiveGraph).AddTxnControlCounters
	internal/stackql/primitivegraph/base_dag.go:103
github.com/stackql/stackql/internal/stackql/execution.(*monoValentExecution).GetExecutor.func1
	internal/stackql/execution/mono_valent_execution.go:1449

This hit the Linux Test (test/registry-mocked) job on #733 (a test-only PR) in the CONCURRENCY_LIMIT: -1 robot pass, on the scenario CTE With Partitioned Window Over Combined Provider Rows. The first pass of the same job (default concurrency) passed, and the same scenario passed on #735 minutes later, so this is a pre-existing intermittent race on main rather than anything in those PRs.

The fix adds a mutex on the graph guarding the append and the getter. Readers (GetTxnControlCounterSlice) only run at plan-build time, so no other call sites change.

Type of change

  • Bug fix (non-breaking change to fix a bug).

Evidence

  • New unit test TestAddTxnControlCountersConcurrent in internal/stackql/primitivegraph. On the unfixed code it loses writes (expected 6400 txn control counters, got 1645) and trips -race; with the guard it passes with -count=5.
  • The existing robot scenario above, run under the CONCURRENCY_LIMIT: -1 pass in CI, is the integration regression check. The race is too narrow to reproduce on demand locally (0 panics in 200 local runs of an 8-arm UNION on the unfixed binary), so no new robot scenario is added; a scenario that only fails on a timing window would be flaky by construction.
  • golangci-lint run ./internal/stackql/primitivegraph/... clean; go build --tags sqlite_stackql ./... clean.

Tech Debt

None added. Files touched: base_dag.go plus the new test file.

🤖 Generated with Claude Code

…nt appends

Executors call AddTxnControlCounters from inside the errgroup that runs
graph nodes, so with an unbounded concurrency limit the arms of a UNION
append to the same slice at the same time. The unguarded append tears
the slice header and surfaces as a nil pointer panic in
standardBasePrimitiveGraph.AddTxnControlCounters, seen in CI on the
"CTE With Partitioned Window Over Combined Provider Rows" scenario
under the CONCURRENCY_LIMIT -1 robot pass (PR #733 run).

Add a mutex around the append and the getter. The new unit test loses
writes on the old code and passes with the guard; it also trips the
race detector on the old code.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@jeffreyaven
jeffreyaven merged commit 587fa76 into main Sep 6, 2026
40 of 41 checks passed
@jeffreyaven
jeffreyaven deleted the fix/txn-counter-slice-race branch September 6, 2026 22:47
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
stackql 0.11.669

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* mirror-publish-git-ident by @jeffreyaven in stackql/stackql#721
* fix: [BUG] query rewriting error using JSON_EXTRACT by @Roshan931 in stackql/stackql#722
* fix: [BUG] View query rewriting issue with `LIKE` and `NOT LIKE` by @Roshan931 in stackql/stackql#723
* consume any-sdk v0.5.5-alpha01: OCI doc-level env vars, body coercion, snake/wire parity wire-through (#705, #726, #725, #710) by @jeffreyaven in stackql/stackql#731
* mcp: adopt protocol revision 2026-07-28 and add otel audit log format; fix build date stamping (#729, #704) by @jeffreyaven in stackql/stackql#732
* ci: skip Docker image build on Dependabot PRs by @jeffreyaven in stackql/stackql#737
* Bump mistune from 3.0.2 to 3.3.3 in /test by @dependabot[bot] in stackql/stackql#724
* fix: guard primitive graph txn control counter slice against concurrent appends by @jeffreyaven in stackql/stackql#736
* ci: move test tooling image stages from bullseye to bookworm by @jeffreyaven in stackql/stackql#743
* Bump cryptography from 43.0.3 to 50.0.0 in /cicd by @dependabot[bot] in stackql/stackql#730
* deps(test): roll up flask 3.1.3, jinja2 3.1.6, requests 2.33.0, pyopenssl 26.0.0 (#739, #740, #741, #742) by @jeffreyaven in stackql/stackql#744
* deps(test): drop unused pyopenssl, pin cryptography 50.0.0, bump urllib3, werkzeug, idna, pytest (#745, #746, #747, #748) by @jeffreyaven in stackql/stackql#749
* docs: add query-before-mutation GCS tutorial by @nirmalpatel008 in stackql/stackql#727
* test: cover relational predicates by @be-student in stackql/stackql#733
* Add unit tests for sqlstream and update PR descriptions by @Sneha41sb in stackql/stackql#735
* Add unit tests for primitive_context, iqlutil, suffix, symtab, serde by @Sneha41sb in stackql/stackql#734
* v0.11 release prep: --output otel inventory snapshots (#738), SHOW CONTRIBUTORS (#320), minor version bump by @jeffreyaven in stackql/stackql#754
* deps(go): bump antchfx/xpath 1.3.6, aws-sdk-go-v2 s3 1.97.3 and eventstream 1.7.8 (#751, #752, #753) by @jeffreyaven in stackql/stackql#756
* Bump github.com/dvsekhvalnov/jose2go from 1.6.0 to 1.7.0 by @dependabot[bot] in stackql/stackql#757

## New Contributors
* @Roshan931 made their first contribution in stackql/stackql#722
* @dependabot[bot] made their first contribution in stackql/stackql#724
* @be-student made their first contribution in stackql/stackql#733

**Full Changelog**: https://github.com/stackql/stackql/compare/v0.10.605...v0.11.669</pre>
  <p>View the full release notes at <a href="https://github.com/stackql/stackql/releases/tag/v0.11.669">https://github.com/stackql/stackql/releases/tag/v0.11.669</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!18655
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.

2 participants