Repository navigation
Conversation
…en idle Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alexluong
force-pushed
the
fix/clickhouse-stale-connections
branch
from
October 30, 2026 14:33
5c7bd09 to
a1803f9
Compare
This branch has not been deployed
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.
When ClickHouse restarts behind a proxy or load balancer, pooled connections can go stale in ways clickhouse-go can't detect on checkout. The proxy either closes the client side only when it next writes, so each stale connection fails one call with
failed to read first block packet: EOF, or it keeps the client side open with nothing behind it, so each stale connection hangs until the caller's deadline or the read timeout. The driver doesn't retry and the other stale connections stay pooled, so the failure repeats once per connection. A process with little ClickHouse traffic keeps its stale connections for up to an hour (the driver's connection lifetime).The idea: drop connections nobody is using, and replace the whole pool as soon as one connection turns out dead.
clickhouse.Newnow returns a wrapper around the driver pool, so callers don't change.CLICKHOUSE_IDLE_CLOSE_SECONDS(default 300) with no ClickHouse call, the pool is closed and the next call dials fresh. A timer drives it, so calls don't pay for a check, and a process making calls never hits it.Query,QueryRow,Select,Ping,QueryFormatandPrepareBatch(no rows are sent beforeSend) run once more on the new pool after a dropped connection.Exec,AsyncInsert,InsertFormatand batchSendreset the pool and return the error without a retry, so rows are never sent twice; callers keep their own retry. A timeout is never retried: it can't tell a dead connection from a slow query.Other changes:
The first call that hits a half-open connection still fails, at its deadline or the read timeout. The pool is replaced then, so the next call works; closing idle pools keeps this rare.
🤖 Generated with Claude Code