Skip to content

Fix race condition in Parquet reader accessing next_subgroup_for_step - #95068

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-parquet-race-next-subgroup-for-step
Jan 25, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-parquet-race-next-subgroup-for-step

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jan 25, 2026 •

Copy link
Copy Markdown
Member

There was a data race between:

  • Thread A assigning a new vector to row_group.next_subgroup_for_step in intersectColumnIndexResultsAndInitSubgroups
  • Thread B reading row_group.next_subgroup_for_step.empty() in the is_privileged_task lambda in scheduleTasksIfNeeded

The fix adds a stage check before accessing the vector. Since next_subgroup_for_step is assigned during OffsetIndex processing and the stage advances to ColumnData only after the assignment, checking stage >= ColumnData with acquire ordering ensures proper synchronization.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC) or LOGICAL_ERROR

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a rare race condition in the Parquet reader.

See https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=95064&sha=701bbbbe6dab5dd19df5195bba04dfc21921a901&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%201%2F2%29
#95064

Version info

  • Merged into: 26.1.1.845

There was a data race between:
- Thread A assigning a new vector to `row_group.next_subgroup_for_step`
  in `intersectColumnIndexResultsAndInitSubgroups`
- Thread B reading `row_group.next_subgroup_for_step.empty()` in the
  `is_privileged_task` lambda in `scheduleTasksIfNeeded`

The fix adds a stage check before accessing the vector. Since
`next_subgroup_for_step` is assigned during `OffsetIndex` processing
and the stage advances to `ColumnData` only after the assignment,
checking `stage >= ColumnData` with acquire ordering ensures proper
synchronization.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jan 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [011c698]

Summary: ❌

job_name test_name status info comment
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: (STID: 2508-11b5) FAIL cidb

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Jan 25, 2026
alexey-milovidov and others added 2 commits January 25, 2026 02:47
This test creates a parquet file with many small row groups and reads it
multiple times to increase the chance of triggering the race condition
between `intersectColumnIndexResultsAndInitSubgroups` (which assigns to
`next_subgroup_for_step`) and `scheduleTasksIfNeeded` (which reads it).

The race is most likely to be caught with ThreadSanitizer.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Jan 25, 2026
@alexey-milovidov
alexey-milovidov merged commit ee5400d into master Jan 25, 2026
129 of 130 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-parquet-race-next-subgroup-for-step branch January 25, 2026 16:40
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jan 25, 2026
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jan 25, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants