Skip to content

Close failed ClickHouse connection pools before retrying - #1578

Merged
Slach merged 3 commits into
Altinity:masterfrom
assimelha:fix/close-failed-clickhouse-pools
Sep 28, 2026
Merged

Slach merged 3 commits into
Altinity:masterfrom
assimelha:fix/close-failed-clickhouse-pools

Conversation

@assimelha

Copy link
Copy Markdown
Contributor

When ClickHouse rejects authentication or the native handshake fails, Connect creates a new driver pool on every retry without closing the pool whose Ping failed. Each pool keeps its drain goroutine and ticker alive, so a command that retries for a long time accumulates resources. Early returns on BreakConnectOnError, shutdown, or FIPS errors also leave the failed pool open.

Close and clear the failed pool immediately after Ping fails, before either waiting to reconnect or returning the original error.

The regression test uses a local TCP server that rejects native handshakes and checks that the driver's pool drain goroutines return to their initial count. It covers immediate failure, shutdown, and a retry followed by shutdown. All three cases fail against the original code and pass with this change.

Validation:

  • go test ./...
  • go test -race ./pkg/clickhouse -count=1
  • go vet ./...

@Slach
Slach merged commit 6903aa2 into Altinity:master Sep 28, 2026
30 checks passed
@Slach

Slach commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

thanks for contribution

@Slach Slach added this to the 2.8.1 milestone Sep 28, 2026
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