Skip to content

Hold the query slot with a connected client in test_read_temporary_tables_on_failure - #129151

Merged
Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-test-read-temporary-tables-on-failure-connected-holder
Nov 4, 2026
Merged

Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-test-read-temporary-tables-on-failure-connected-holder

Conversation

@groeneai

@groeneai groeneai commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #127149

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):

...

Description

test_read_temporary_tables_on_failure/test.py::test_different_versions fails on every master commit since #127149 in Integration tests (amd_tsan / amd_msan / amd_asan_ubsan, db disk, 7/8) with Failed: DID NOT RAISE <class 'helpers.client.QueryRuntimeException'> (report).

The test fills the user's only max_concurrent_queries_for_user slot with a long sleepEachRow query and then kills its client after 5 s, expecting the query to keep running. Since #127149 the server cancels a query whose client is gone, and sleep stops within a second, so the slot is free before SELECT 1 arrives. arm_binary usually wins that race (green on the same commits), and it is the only flavour that ran this test in #127149's own CI.

Now the slot is held by a background request whose client stays connected. The test waits until it appears in system.processes, runs the unchanged SELECT 1 with max_concurrent_queries_for_user = 1, then stops the holder with KILL QUERY ... SYNC. The SELECT 1 leg and the three log assertions (the server must skip the unread temporary-tables packet after TOO_MANY_SIMULTANEOUS_QUERIES) are unchanged, and nothing depends on timing anymore.

Validation (local debug build): the old test with a 3 s pause before SELECT 1 fails 3/3 on current master and passes 3/3 on a build before #127149. The new test passes 50/50 in 5 sessions with randomized settings, 3/3 with a 5 s pause, and 5/5 on an ASan build before #127149. With skipData removed from TCPHandler::runImpl it fails on Unexpected packet.


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

Version info

  • Merged into: 26.11.1.1324-master (included in 26.11 and later)

…bles_on_failure

The test filled the user's only max_concurrent_queries_for_user slot with a
long sleepEachRow query and killed its client after 5 s, relying on the
orphaned query to keep running so that the next SELECT 1 fails with
TOO_MANY_SIMULTANEOUS_QUERIES before its external tables are read.

Since ClickHouse#127149 the server cancels a query whose TCP client is gone, and sleep
stops at its next 1 s chunk, so the slot is free before SELECT 1 arrives.
Sanitizer builds lose that race every time (master red in amd_tsan, amd_msan
and amd_asan_ubsan integration tests), arm_binary usually wins it.

Hold the slot with a background request whose client stays connected, wait
until it is in system.processes, run the unchanged SELECT 1, then stop the
holder with KILL QUERY ... SYNC. The log assertions that are the purpose of
the test are unchanged.

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

groeneai commented Nov 4, 2026

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

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).

# Sev Finding Verdict Evidence / action
1 💡 long_query.get_error() does not check that the holder ended with QUERY_WAS_CANCELLED noted, not blocking get_error() already raises if the holder succeeded; in all 50 local runs it ended with QUERY_WAS_CANCELLED and no holder leaked between iterations

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-8:20261104-013600

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The old test with time.sleep(3) before the SELECT 1 block fails 3/3 (DID NOT RAISE) on current master and passes 3/3 on a build before #127149.
b Root cause explained? Yes. The slot holder's client is killed after 5 s; since #127149 the server cancels that query and sleep stops within 1 s, so the slot is free and SELECT 1 succeeds. Server log: Cancelling the query (reason: CANCELLED_BY_USER), then SELECT 1 processed in 0.002 s.
c Fix matches root cause? Yes. The broken premise was "a killed client leaves its query running"; the slot is now held by a connected client and released with KILL QUERY ... SYNC.
d Test intent preserved / new tests added? Yes. The SELECT 1 leg and the three log assertions are unchanged; with skipData removed from TCPHandler::runImpl the new test fails on Unexpected packet Data received from client.
e Both directions demonstrated? Yes. Old test: fails on master, passes before #127149. New test: 50/50 on master (5 sessions, randomized settings), 3/3 with a 5 s pause, 5/5 on an ASan build before #127149.
f Fix is general across code paths? Yes. Other tests using a client timeout assert different things (dictionary loading, client-side timeout) and pass on master since the merge.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only change; the holder is one block under any randomized max_block_size).
h Backward compatible? (maintainer-approved exception only) Yes. No source, setting or format change; the test passes on servers before and after #127149.
i Invariants and contracts preserved? Yes. The system.processes probe and KILL QUERY are not counted against max_concurrent_queries_for_user; the holder is killed and its client reaped before the log checks, so repeated runs do not leak a slot.

Session id: cron:clickhouse-impl-slot-41:20261104-011300

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @CheSema, could you review this and add the can be tested label so CI runs? Since #127149 the server cancels a query whose client was killed, so this test's slot holder is gone before SELECT 1 arrives; the slot is now held by a background request whose client stays connected, then removed with KILL QUERY ... SYNC.

@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dd4ac12]

Summary: ✅


AI Review

Summary

This PR keeps the concurrency slot occupied by a connected background client in test_different_versions, waits for its query in system.processes, and cancels and reaps it after checking rejection of SELECT 1. The existing packet-handling assertions are preserved. No actionable findings.

Missing context / blind spots
  • ⚠️ No ClickHouse binary is available locally, so the integration test was not rerun during this review. The sanitizer builds for this head are still queued; completed targeted CI runs would independently confirm the repeated-run and negative-control results documented in the PR.
Final Verdict

Status: ✅ Approve

@Algunenano
Algunenano added this pull request to the merge queue Nov 4, 2026
Merged via the queue into ClickHouse:master with commit 5f014d8 Nov 4, 2026
366 of 367 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 4, 2026
@clickhouse-gh clickhouse-gh Bot added comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... 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

can be tested Allows running workflows for external contributors comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... pr-ci 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