Skip to content

Fix flaky test 03821_drop_workload_during_query_race - #126345

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-03821-drop-workload-error-filter
Oct 19, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-03821-drop-workload-error-filter

Conversation

@groeneai

@groeneai groeneai commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #123341

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Not required.

Description

Stateless tests (arm_binary, s3 storage, DBReplicated, sequential) on master 663364fe5ef failed with having exception in stdout: the stack frames of RequestQueue::enqueueRequest <- CPULeaseAllocation, then the client's Received exception from server and (query: ...) lines.

Since #123341, DROP WORKLOAD purges the dropped workload's queue. A racing query that still holds a link to that queue now fails with INVALID_SCHEDULER_NODE when it allocates CPU. That is intended (DropWorkloadFailsPendingRequests in #123341 expects the throw), and the test already lists this code as expected. But the test filtered the output line by line with grep -v. A failed query also prints the server's error log (forwarded by --send_logs_level=warning) with its stack trace, plus the client's header and query lines, and only the lines that contain the code were dropped. Before #123341 no racing query failed, so the broken filter never showed.

Now thread_query captures each query's whole output and prints it only if it contains none of the expected codes. The expected codes are unchanged, and any other output still fails the test.

Validation (debug build of master with #123341, 300 sequential randomized runs per arm):

  • Unmodified test: 9/300 fail with the CI signature. The failing runs are exactly the runs whose query_log has a query failed with code 672. On a master build from before Fix possible crash due to use-after-free of memory reservation after DROP WORKLOAD #123341: 300/300 OK, no such query.
  • New test: 300/300 OK while 9 of those runs hit code 672; 50/50 OK in a separate randomized run.
  • If the racing query is changed to throw an unexpected error, the new test fails 3/3.

Workflow [PR]
Sync PR [sync-upstream/pr/126345]

Version info

  • Merged into: 26.11.1.185-master (included in 26.11 and later)
  • Backported to: 26.10.3.23

Since ClickHouse#123341, DROP WORKLOAD purges the dropped workload's queue, so a racing
query that still links to it fails with INVALID_SCHEDULER_NODE when it
allocates CPU. The test expects that code, but filtered the client output
line by line with `grep -v`. A failed query also prints the server's error
log, forwarded by --send_logs_level=warning, with its stack trace, plus the
client's "Received exception from server" and "(query: ...)" lines. Only the
lines that carry the code were dropped, so the stack frames reached stdout
and the runner reported "having exception in stdout".

Capture each query's whole output and print it only if it contains none of
the expected codes. Any other output still fails the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

Own cold review + Gate B (codex) on 741c1e5fbdf3c: 0 blockers, 0 majors.

Finding Verdict
💡 Whole-output matching also hides any other log line printed by a query that failed with an expected code. Noted, not blocking. The INVALID_SCHEDULER_NODE failure seen in CI happens when the pipeline allocates CPU, before any processing. The crash this test guards against is still caught by the final SELECT 1, and an unexpected error still fails the test (3/3).
💡 The There is no resource pattern no longer matches any message in src/. Noted, not blocking. Kept to leave the original expected list unchanged.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. With the old line filter, a query failing with INVALID_SCHEDULER_NODE leaks its forwarded server log stack frames and the client's Received exception from server line on every call. The race itself fails 9/300 runs on a debug build with #123341.
b Root cause explained? #123341 purges a dropped workload's queue at DROP WORKLOAD, so a racing query that still links to it gets INVALID_SCHEDULER_NODE from RequestQueue::enqueueRequest (intended). The test drops only the lines that carry the code, so the stack frames of the forwarded <Error> executeQuery log reach stdout.
c Fix matches root cause? Yes. Each query's whole output is matched against the expected codes. No tags, no widened bounds, no stderr suppression.
d Test intent preserved / new tests added? Yes. Same race, same liveness check. Unexpected output still fails the test (scratch copy throwing an unexpected error: 3/3 FAIL). Test-only fix.
e Both directions demonstrated? Before: 9/300 FAIL, each failing run being one with a query failed with code 672. After: 300/300 OK while 9 runs hit code 672; 50/50 OK randomized. Pre-#123341 build: 300/300 OK, no code 672.
f Fix is general across code paths? Sibling workload tests either discard the racing query's stderr or drop only after wait. No other workload test failed on master since #123341.
g Fix generalizes across inputs (params/datatypes/wrappers)? Both expected codes (INVALID_SCHEDULER_NODE, RESOURCE_ACCESS_DENIED) are matched whole. Randomized settings over 350 runs. Type wrappers N/A.
h Backward compatible? (maintainer-approved exception only) N/A, test-only.
i Invariants and contracts preserved? Per-call timeout bounds, cleanup trap, tags and .reference unchanged.

Session id: cron:clickhouse-impl-slot-7:20261016-172600

@clickhouse-gh

clickhouse-gh Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [741c1e5]

Summary: ✅


AI Review

Summary

This PR fixes false failures in 03821_drop_workload_during_query_race by filtering complete multiline reports for the already-expected workload errors. The current diff and prior discussion reveal no actionable findings; the reported repeated race runs and unexpected-error checks provide adequate evidence for this test-only change.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @serxa, could you review this? Since #123341 a query racing DROP WORKLOAD can fail with the expected INVALID_SCHEDULER_NODE, and the per-line grep -v let the forwarded server log stack trace through to stdout. The test now drops the whole output of a query that failed with an expected code.

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 16, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 17, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

The 26.10 backport of #123341 (#127462) merged on 2026-10-22, but this test fix is not on 26.10, and the test now fails there with the signature fixed here: 26.10 CI report (CPULeaseAllocation::renew stack frames in stdout).

Could v26.10-must-backport be added here? v26.8-must-backport would also cover 26.8 and 26.9, where the #123341 cherry-picks (#127460, #127461) are still open and would bring the same failure once they merge. The change is test-only, and the test file on 26.8, 26.9 and 26.10 is identical to this PR's base version, so the cherry-pick is clean.

@robot-clickhouse robot-clickhouse added pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Oct 29, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 29, 2026
Backport #126345 to 26.10: Fix flaky test `03821_drop_workload_during_query_race`
@PedroTadim PedroTadim added v26.6-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR v26.10-must-backport labels Oct 30, 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 Oct 30, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 30, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 30, 2026
Backport #126345 to 26.9: Fix flaky test `03821_drop_workload_during_query_race`
clickhouse-gh Bot added a commit that referenced this pull request Oct 30, 2026
Backport #126345 to 26.8: Fix flaky test `03821_drop_workload_during_query_race`
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
@clickhouse-gh clickhouse-gh Bot added comp-scheduler Workload scheduler and resource management: CPU/IO/memory scheduling, concurrency control, worklo... and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release can be tested Allows running workflows for external contributors comp-scheduler Workload scheduler and resource management: CPU/IO/memory scheduling, concurrency control, worklo... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci 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 v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants