Skip to content

fix(clickhouse): stop HTTP Native stream desync on connect driver - #8248

Open
sentry[bot] wants to merge 13 commits into
masterfrom
seer/fix-clickhouse-connect-dynamic-type
Open

fix(clickhouse): stop HTTP Native stream desync on connect driver#8248
sentry[bot] wants to merge 13 commits into
masterfrom
seer/fix-clickhouse-connect-dynamic-type

Conversation

@sentry

@sentry sentry Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

EAP queries on the clickhouse-connect (HTTP) driver fail intermittently with:

Unrecognized ClickHouse type base: <attribute values>

This is a Native binary framing desync: the decoder reads row payload (attribute strings) as column type names. HTTP-only, unrelated to Dynamic casting.

Changes

  • Disable client_protocol_version by default via sentry-option clickhouse_connect_use_protocol_version (plain Native framing; safer when hops strip the setting)
  • Pin compress="lz4" and num_pools=1 (single LB origin)
  • Translate StreamFailureError and desync into ClickhouseError
  • Clear keep-alives after transport/stream/desync failures (no query retry)
  • Metrics: clickhouse.connect.connection_error, stream_failure, stream_desync
  • Sentry-options for pool size and timeouts:
    • clickhouse_connect_pool_size
    • clickhouse_connect_connect_timeout (0 = constructor default)
    • clickhouse_connect_send_receive_timeout (0 = profile/constructor value)

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes SNUBA-BMW

@sentry sentry Bot changed the title fix(clickhouse): Disable cast_string_to_dynamic_use_inference for clickhouse-connect fix(clickhouse): Resolve mypy errors in connect.py Jul 31, 2026
@sentry
sentry Bot marked this pull request as ready for review July 31, 2026 21:29
@sentry
sentry Bot requested a review from phacops July 31, 2026 21:29
@sentry
sentry Bot requested a review from a team as a code owner July 31, 2026 21:29
@phacops
phacops force-pushed the seer/fix-clickhouse-connect-dynamic-type branch from 7b12720 to fb7b691 Compare August 1, 2026 03:57
@phacops phacops changed the title fix(clickhouse): Resolve mypy errors in connect.py fix(clickhouse): stop HTTP Native stream desync on connect driver Aug 1, 2026
EAP queries over clickhouse-connect were failing with
`Unrecognized ClickHouse type base: <attribute values>` because the
HTTP Native decoder lost framing and read row payload as type names.
Disable client_protocol_version negotiation (fragile on HTTP), pin
lz4 compression, translate StreamFailureError, and retry once after
resetting the cached client on desync.
@phacops
phacops force-pushed the seer/fix-clickhouse-connect-dynamic-type branch from fb7b691 to 9ddaae0 Compare August 1, 2026 03:58
phacops added 12 commits July 31, 2026 21:03
Replace the hardcoded use_protocol_version=False with
clickhouse_connect_use_protocol_version (default false), applied when
the HTTP client is created so it can be flipped without a deploy.
Migrate clickhouse_connect_pool_size off runtime state config onto a
sentry-option (default 25), matching the rest of the connect driver
knobs.
Apply clickhouse_connect_use_protocol_version once at module import,
matching invalid_setting_action, instead of re-setting it on every
client create.
Emit clickhouse.connect.* for connection errors and stream desync
so they sit next to clickhouse.native.* instead of under a mixed
clickhouse.connect.<unprefixed> namespace.
Keep metric names unprefixed; clickhouse.connect comes from the
wrapper, same as before.
Retry once after close_connections() instead of rebuilding the client,
and fold the retry into a short loop.
Each ClickhouseConnectPool talks to one LB origin, so num_pools=1 is
enough; the second slot was unused.
Surface desync and stream failures as ClickhouseError immediately;
keep metrics, drop connection reset/retry.
On transport errors, stream failures, and Native desync, clear the
HTTP connection pool before surfacing ClickhouseError so the next
query does not reuse a poisoned socket. Still no query retry.
Expose clickhouse_connect_connect_timeout and
clickhouse_connect_send_receive_timeout (0 keeps constructor/profile
values) for HTTP client creation.
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.

1 participant