Skip to content

Retry ClickHouse ping with backoff on connect - #5103

Open
dtunikov wants to merge 5 commits into
mainfrom
retry-clickhouse-ping
Open

dtunikov wants to merge 5 commits into
mainfrom
retry-clickhouse-ping

Conversation

@dtunikov

@dtunikov dtunikov commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Connecting to a ClickHouse peer fails if the initial ping hits a transient network error. In prod this happens several times a day across multiple ClickPipes: failed to ping to ClickHouse peer: read tcp ...: read: connection reset by peer.

  • Add peerdb_clickhouse.Ping, which retries up to 5 times with the same backoff as Exec/Query (1s, 6s, 11s, 16s). Network errors are always retried; server exceptions that aren't retryable, such as auth failures, return right away.
  • Move the retry loop shared by Exec, Query, QueryRow and Ping into a generic withRetry helper. Retries are now logged at warn level instead of info.

Added unit tests TestPingRetriesConnectionReset and TestPingDoesNotRetryAuthFailure.

🤖 Generated with Claude Code

dtunikov and others added 2 commits November 20, 2026 10:49
Transient connection resets during the initial ping fail PeerCreate for
ClickPipes multiple times a day. Retry transient errors up to 5 times,
but return non-retryable server exceptions (e.g. auth failures) immediately.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dtunikov
dtunikov marked this pull request as ready for review November 20, 2026 09:51
@dtunikov
dtunikov requested a review from a team as a code owner November 20, 2026 09:51
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 20, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 20, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@gheorghepucea gheorghepucea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work! I like the code refactoring as well, just left a comment about more test cases.

import (
"context"
"errors"
"net"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you add Ping tests for these cases?

  1. A permanent network error, such as DNS "no such host" or a TLSfailure, isn't retried?
  2. An unreachable host, where packets are silently dropped, isn't retried?
  3. A canceled context stops retries?

@jgao54 jgao54 Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for 1/2, unless we do integrations testing, these belong to unit tests for isRetryableException imo, but is allso not super interesting. could add an integrations test and use toxiproxy to mimic bad network.

+1 for context cancellation coverage

Comment on lines +76 to +77
// withRetry runs fn up to 5 times with backoff while shouldRetry returns true for its error.
// On context cancellation during backoff it returns the last result along with ctx.Err().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: the code is pretty self-explanatory, recommend removing the comment
(also the last result is typically ignored and not used on context cancellation, so highlighting this in comment is a bit confusing imo)

This branch has not been deployed

No deployments
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.

3 participants