Skip to content

Fix flaky test test_under_max_waiting_queries_limit - #97671

Closed
alexey-milovidov wants to merge 5 commits into
masterfrom
fix-test_under_max_waiting_queries_limit
Closed

alexey-milovidov wants to merge 5 commits into
masterfrom
fix-test_under_max_waiting_queries_limit

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 22, 2026 •

Copy link
Copy Markdown
Member

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

...

The test test_under_max_waiting_queries_limit has a race condition: with max_concurrent_queries=1, max_waiting_queries=6, and 7 threads, the queue is at its exact boundary. Since ResourceRequest::finish is asynchronous (it posts an activation event to the scheduler's EventQueue), there is a window between a query finishing and the scheduler dequeuing the next waiting request from FifoQueue. During this window, the freed thread can loop and try to enqueue a new request while the queue still has 6 entries, causing a SERVER_OVERLOADED exception.

Increase max_waiting_queries to 100 to provide headroom for the async scheduler processing. The test still verifies that queries can wait successfully when there is sufficient queue capacity.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8c2e90020b4a9507478da3ebfa1c31226ffc8da4&name_0=MasterCI&name_1=Integration%20tests%20%28amd_binary%2C%204%2F5%29

🤖 Generated with Claude Code

The test had a race condition: with `max_concurrent_queries=1`,
`max_waiting_queries=6`, and 7 threads, the queue was at its
exact boundary. Since `ResourceRequest::finish` is asynchronous
(it posts an activation event to the scheduler's `EventQueue`),
there is a window between a query finishing and the scheduler
dequeuing the next waiting request from `FifoQueue`. During this
window, the freed thread can loop and try to enqueue a new request
while the queue still has 6 entries, causing a `SERVER_OVERLOADED`
exception.

Increase `max_waiting_queries` to 100 to provide headroom for the
async scheduler processing. The test still verifies that queries
can wait successfully when there is sufficient queue capacity.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8c2e90020b4a9507478da3ebfa1c31226ffc8da4&name_0=MasterCI&name_1=Integration%20tests%20%28amd_binary%2C%204%2F5%29

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

clickhouse-gh Bot commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9518674]

Summary: ✅

alexey-milovidov and others added 3 commits February 23, 2026 02:30
Synchronous DROP/DETACH (triggered by `database_atomic_wait_for_drop_and_detach_synchronously`
setting or explicit `SYNC` keyword) inside a transaction creates a deadlock:
the transaction holds `StoragePtr` references preventing the background cleanup
from finalizing the dropped tables (checked via `isSharedPtrUnique`), while the
query waits for that cleanup in `waitTableFinallyDropped`.

This was observed in stress tests where `implicit_transaction=1` and
`database_atomic_wait_for_drop_and_detach_synchronously=1` are randomly
combined, causing `DROP DATABASE` to hang indefinitely.

Now, when a synchronous DROP/DETACH is attempted inside a transaction, we either
throw an exception (if `throw_on_unsupported_query_inside_transaction` is set)
or silently fall back to asynchronous mode.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97670&sha=709389103955ac69cec0ec90baa446fb0201870e&name_0=PR&name_1=Stress%20test%20%28arm_asan%2C%20s3%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…:ClickHouse/ClickHouse into fix-test_under_max_waiting_queries_limit
@alexey-milovidov alexey-milovidov changed the title Fix flaky test test_under_max_waiting_queries_limit Fix flaky test and deadlock between synchronous DROP and transactions Feb 23, 2026
@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-ci labels Feb 23, 2026
@alexey-milovidov alexey-milovidov changed the title Fix flaky test and deadlock between synchronous DROP and transactions Fix flaky test test_under_max_waiting_queries_limit Feb 23, 2026
@clickhouse-gh clickhouse-gh Bot added pr-ci and removed pr-bugfix Pull request with bugfix, not backported by default labels Feb 23, 2026

@serxa serxa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pointless, test now does nothing

@alexey-milovidov alexey-milovidov self-assigned this Feb 23, 2026
alexey-milovidov added a commit that referenced this pull request Feb 23, 2026
The test has a race condition: with `max_concurrent_queries=1`,
`max_waiting_queries=6`, and 7 threads, the queue is at its exact
boundary. Since `ResourceRequest::finish` is asynchronous, there is
a window between a query finishing and the scheduler dequeuing the
next waiting request, causing sporadic `SERVER_OVERLOADED` exceptions.

Reference: #97671

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants