Skip to content

Fix flaky test_tcp_handler_connection_limits - #113530

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-flaky-tcp-handler-connection-limits
Aug 6, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-flaky-tcp-handler-connection-limits

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

test_tcp_handler_connection_limits counted every Done processing connection. message in the server log and asserted that its own connection was the only one that closed. Two unrelated connections break that count.

The readiness probe of cluster.start connects to the TCP port and closes it without sending any data. The port is bound and listening from createServers onwards, so the kernel completes the handshake long before the server starts accepting; the probe is served only once startup finishes, which can be after the test has already sampled the initial count. That is the MSan failure, where startup takes seconds:

Application: Ready for connections.
TCPHandlerFactory: TCP Request. Address: 172.16.2.1:59612
TCPHandler: Client has not sent any data.
TCPHandler: Done processing connection.     <-- counted, but not sampled

Also, clickhouse-client reconnects after the server drops it, so a single run of the test can close two connections by itself. That is the shape of the earlier failures, where both tests reported a delta of two.

Count the connections closed because a limit was reached instead - the server logs Closing connection due to limits exactly once per such connection, and the reason distinguishes the query-count limit from the time limit. Neither the readiness probe nor a reconnecting client reaches a limit: query_count and connection_timer are per-connection, so a fresh connection starts from zero. With the count no longer polluted by startup connections, the sleep that tried to wait them out is not needed.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=7d22d13ab50ff1474fad83ba8e19db7b60c24412&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%203%2F8%29

Changelog category (leave one):

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

The test counted every `Done processing connection.` message in the server log
and asserted that its own connection was the only one that closed. Two
unrelated connections break that count:

* The readiness probe of `cluster.start` connects to the TCP port and closes it
  without sending any data. The port is bound and listening from `createServers`
  onwards, so the kernel completes the handshake long before the server starts
  accepting; the probe is served only once startup finishes, which can be after
  the test has already sampled the initial count. This is what fails on MSan,
  where startup takes seconds:

      Application: Ready for connections.
      TCPHandlerFactory: TCP Request. Address: 172.16.2.1:59612
      TCPHandler: Client has not sent any data.
      TCPHandler: Done processing connection.     <-- counted, but not sampled

* `clickhouse-client` reconnects after the server drops it, so a single run of
  the test can close two connections by itself. That is the shape of the earlier
  failures, where both tests reported a delta of two.

Count the connections closed *because a limit was reached* instead - the server
logs `Closing connection due to limits` exactly once per such connection, and
the reason distinguishes the query-count limit from the time limit. Neither the
readiness probe nor a reconnecting client reaches a limit: `query_count` and
`connection_timer` are per-connection, so a fresh connection starts from zero.

With the count no longer polluted by startup connections, the `sleep` that tried
to wait them out is not needed.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=7d22d13ab50ff1474fad83ba8e19db7b60c24412&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%203%2F8%29

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0e8920b]

Summary: ✅


AI Review

Summary

This PR hardens tests/integration/test_tcp_handler_connection_limits/test.py against startup and client-reconnect noise by waiting for one successful query after cluster.start and by counting only Closing connection due to limits log lines keyed by queries= / elapsed= instead of every Done processing connection. message. I did not find a new correctness or stability issue in the current patch.

Final Verdict

✅ No blocking review findings. No new inline comments were posted.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 5, 2026
`cluster.start` returns as soon as the TCP handshake to the port succeeds, which
the kernel completes while the server may still be starting up, so a test's
connection can sit in the accept backlog behind the rest of the startup. Waiting
for one query to go through is the condition the removed `sleep` was guessing at.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks.

@alexey-milovidov alexey-milovidov self-assigned this Aug 5, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 5, 2026
Merged via the queue into master with commit 40af175 Aug 6, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-flaky-tcp-handler-connection-limits branch August 6, 2026 00:24
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 6, 2026
alexey-milovidov added a commit that referenced this pull request Aug 6, 2026
…ded-by-query-limit

Pulls in #113530 (merged 2026-08-06), the fix for the unrelated flaky
test_tcp_handler_connection_limits::test_query_count_limit (issue #113555)
that was the only red on the previous head.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants