Repository navigation
Fix MySQL connect_timeout not taking effect under the query profiler - #109592
Merged
Merged
Conversation
Bump mariadb-connector-c: pvio_socket_wait_io_or_timeout restarted poll with the full original timeout after EINTR, resetting the deadline on every signal. ClickHouse query threads receive sampling-profiler timer signals (query_profiler_real_time_period_ns, default 1 s) without SA_RESTART, so with a signal period not exceeding connect_timeout the poll never expired: a connection attempt to a blackholed host (SYN dropped, e.g. 192.0.2.1) hung until the kernel exhausted SYN retransmissions (~130 s) regardless of connect_timeout. The connector now re-polls with the remaining time and reports ETIMEDOUT when the budget is exhausted. This also bounds the TLS handshake and read/write waits that go through the same function, and cuts test 04210_show_remote_databases_in_system_tables from ~135 s to ~4 s. Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
|
Workflow [PR], commit [2c18d21] Summary: ✅
AI ReviewSummaryThis PR updates the bundled Final VerdictStatus: ✅ Approve |
The previous 60 s bound only caught the full ~135 s regression; a partial regression (e.g. capping the EINTR retries instead of decrementing the remaining budget) could leave the timeout broken while keeping the test green. The fixed ATTACH takes ~1 s. Co-Authored-By: Claude Fable 5 <[email protected]>
pull Bot
pushed a commit
to sonvt1710/ClickHouse
that referenced
this pull request
Aug 20, 2026
ReadBufferFromFileDescriptor::poll restarted the interrupted poll with the full original timeout after EINTR, resetting the deadline on every signal. Query threads receive periodic query-profiler timer signals (SA_RESTART does not apply to poll), so with a signal period not exceeding the timeout the poll never expired while the fd stayed silent. This reaches users through the streaming-insert block wait (input_format_max_block_wait_ms in IRowInputFormat::read): a stalled input source could delay the partial-block flush indefinitely under the profiler instead of flushing when the wait limit is reached. Re-poll with the remaining time, computed in microseconds from a single monotonic anchor: per-retry whole-millisecond accounting would truncate a sub-millisecond interval to zero and make no progress. The unit test drives both cadences (10 ms and 0.5 ms) with a per-thread kernel timer (SIGEV_THREAD_ID), the same mechanism the query profiler uses. Same defect class as the mariadb-connector-c connect_timeout fix (ClickHouse#109592, upstream https://jira.mariadb.org/browse/CONC-834). Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…t-timeout-blackhole Fix MySQL connect_timeout not taking effect under the query profiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #109472
Related: https://jira.mariadb.org/browse/CONC-834
Problem. The MySQL
connect_timeoutsetting (and the read/write timeouts) can be silently ignored inside ClickHouse. A connection attempt to an unresponsive MySQL server — one that drops packets instead of refusing the connection — hangs for ~135 seconds (the kernel SYN-retransmission limit) even withconnect_timeout = 1:Any query thread touching such a server blocks for minutes while holding locks (e.g.
DatabaseMySQL::mutex), and stateless test04210_show_remote_databases_in_system_tablesspent ~135 seconds per run on exactly this.Root cause.
pvio_socket_wait_io_or_timeoutin mariadb-connector-c restartspollwith the full original timeout afterEINTR. ClickHouse query threads receive sampling-profiler timer signals (query_profiler_real_time_period_ns, default 1 s) installed withoutSA_RESTART, so whenever the signal period does not exceed the timeout, the poll deadline is reset by every signal and never expires; with a blackholed host the poll returns only when the kernel exhausts SYN retransmissions. Verified with a C repro against the bundled library: no signals → fails in exactly 1.00 s; with a 100 ms periodic signal → 135.32 s and 1353EINTRs, matching the in-server measurement. The connector and themysqlxxoption plumbing are otherwise correct.Fix. Bump the
mariadb-connector-csubmodule to a fork commit (ClickHouse/mariadb-connector-c@111ec1a5, brancheintr-connect-timeout) that tracks the deadline withCLOCK_MONOTONICand re-polls with the remaining time afterEINTR, reportingETIMEDOUTonce the budget is exhausted. One fix covers all callers ofwait_io_or_timeout: TCP connect, TLS handshake, and read/write waits. The same defect existed upstream; reported as CONC-834 and the suggested patch was accepted the same day (Closed/Fixed, fixVersions 3.3.20 and 3.4.10), so the fork patch can be dropped at the next connector version bump.The regression test
04507_mysql_connect_timeout_under_profilerattaches a MySQL database pointing at a blackholed TEST-NET-1 address withconnect_timeout = 1under a 100 ms query profiler and asserts viasystem.query_logthat theATTACHis bounded by the timeout (fixed ≈ 2 s, unfixed ≈ 135 s). Side effect:04210_show_remote_databases_in_system_tablesdrops from ~135 s to ~4 s.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the MySQL
connect_timeout, read and write timeouts not taking effect: a connection attempt to an unresponsive MySQL server could hang for more than two minutes even withconnect_timeout = 1, because the sampling query profiler's periodic signals kept resetting the MySQL client's internal poll deadline.Version info
26.7.1.637(included in26.7and later)