Skip to content

fix: bound ClickHouse requests, close idle sockets - #249

Merged
catinspace-au merged 2 commits into
mainfrom
fix/clickhouse-client-timeouts
Oct 12, 2026
Merged

catinspace-au merged 2 commits into
mainfrom
fix/clickhouse-client-timeouts

Conversation

@catinspace-au

Copy link
Copy Markdown
Contributor

The loader's ClickHouse client had no client-side bound on anything, and its idle pool never closed a connection.

  • connect_timeout_ms and request_timeout_ms were declared but nothing read them, so an insert to a stalled ClickHouse waited on ClickHouse's own 300 s timeouts.
  • The fork's pool set a 2 s idle timeout but no pool timer, and hyper-util only sweeps idle connections when it has one. ClickHouse closed them instead and logged code 209 each time.

What changes:

  • build_client hands the fork its own hyper client through Client::with_http_client: connect timeout, pool timer with the 2 s idle timeout, and HTTPS verified against the system trust store with the same aws-lc-rs provider and native roots as before. No fork change: the fork repo is archived, and Pre-GA bug sweep: the clickhouse patch #133 still stands.
  • clickhouse.connect_timeout_ms (5 s), clickhouse.request_timeout_ms (30 s, queries and the insert upload) and the new clickhouse.insert_timeout_ms (60 s, the wait for the server's answer) are real config keys. A zero is refused at startup.
  • A timed-out insert or schema fetch goes straight back to be held, offset uncommitted, instead of retrying inside the cycle with the event loop blocked.
  • 60 s is about 270x the ClickHouse CPU cost of a 20,000-row flush (91,000 rows per CPU-second measured), and two rounds of timed-out inserts still fit Kafka's 300 s max.poll.interval.ms.
  • docs/clickhouse/TLS.md and docs/CONFIGURATION.md named tls_ca_file / tls_ca_exclusive keys no code reads. They now describe the system trust store and SSL_CERT_FILE.

Tests:

  • Idle connection closes about 2 s after its last request; a connect to a full accept queue and an unanswered query each give up at a 300 ms bound. All three ran past 8-10 s before the change.
  • An unanswered insert, RowBinary and JSONEachRow, comes back as a retry with its rows and offsets after one 300 ms attempt.
  • Real Kafka and ClickHouse behind a proxy that never answers: the insert times out and is resent, the commit stays below it, and it lands once ClickHouse answers. Without the insert bound the loader sent one insert in 45 s.
  • Real ClickHouse with a private-CA cert: accepted with that CA in SSL_CERT_FILE, refused with an unrelated CA, with the platform store alone, and on a host name the cert does not list. Plain HTTP still works.

Done when the released image runs with the bounds on and ClickHouse stops logging 209 for idle loader connections.

connect_timeout_ms and request_timeout_ms were declared but no client read them, so an insert to a stalled ClickHouse had no client-side bound. The pool's 2 s idle timeout never fired either: hyper-util sweeps idle connections only when the pool has a timer, so ClickHouse closed them and logged code 209 each time.

- build_client hands the fork its own hyper client through Client::with_http_client: connect timeout, a pool timer with the 2 s idle timeout, and HTTPS verified against the system trust store with the aws-lc-rs provider and native roots, as before.
- clickhouse.connect_timeout_ms (5 s), request_timeout_ms (30 s, queries and the insert upload) and the new insert_timeout_ms (60 s, the wait for the server's answer) reach the client. A zero is refused at startup.
- A timed-out insert or schema fetch returns straight to the hold, its offset uncommitted, instead of retrying inside the flush cycle.
- The TLS docs named tls_ca_file and tls_ca_exclusive keys no code reads; they now describe the system trust store and SSL_CERT_FILE.
Comment thread tests/integration/clickhouse_tls.rs Fixed
CodeQL's sensitive-name heuristic reads a variable called trusted as a secret, and flagged the test's assert message that prints it.
@catinspace-au
catinspace-au merged commit 4673b76 into main Oct 12, 2026
17 checks passed
@catinspace-au
catinspace-au deleted the fix/clickhouse-client-timeouts branch October 12, 2026 05:13
@github-actions

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants