clickhouse-go
clickhouse-go copied to clipboard
Connection Issue: ClickHouse Go Driver vs. CLI
Observed
-
Connecting with the
clickhouse-godriver to ClickHouse Cloud (Azure & GCP) fails with aconnection reset by peererror. - Self-hosted ClickHouse deployments work perfectly fine with the Go driver.
-
The official ClickHouse CLI (
clickhouse-client) is able to connect to both cloud and self-hosted environments without any issues.
Expected behaviour
- The Go driver should connect successfully to ClickHouse Cloud deployments (similar to both self-hosted and the CLI client).
Code example
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/ClickHouse/clickhouse-go/v2"
)
func main() {
connStr := "clickhouse://<user>:<password>@<cloud-host>:9440/<database>?secure=true"
db, err := sql.Open("clickhouse", connStr)
if err != nil {
log.Fatalf("sql.Open error: %v", err)
}
defer db.Close()
if err := db.Ping(); err != nil {
log.Fatalf("Ping error: %v", err)
}
var one int
if err := db.QueryRow("SELECT 1").Scan(&one); err != nil {
log.Fatalf("QueryRow error: %v", err)
}
fmt.Println("Result:", one)
}
Error log
[clickhouse][4.152.12.124:9440][id=4][handshake] -> 0.0.0
[clickhouse-std][opener] [connect] error connecting to xxxxxx.eastus2.azure.clickhouse.cloud:9440 on connection 4: read: read tcp xxx.168.68.110:53028->x.xxx.xx.124:9440: read: connection reset by peer
Details
Environment
- [x]
clickhouse-goversion: v2.40.3 - [x] Interface: ClickHouse API /
database/sqlcompatible driver: database/sql - [x] Go version: 1.24.0
- [x] Operating system: MacOS/Linux
- [ ] ClickHouse version:
- [x] Is it a ClickHouse Cloud? Yes (Azure & GCP)
- [ ] ClickHouse Server non-default settings, if any:
- [ ]
CREATE TABLEstatements for tables involved: - [ ] Sample data for all these tables, use [clickhouse-obfuscator](https://github.com/ClickHouse/ClickHouse/blob/master/programs/obfuscator/Obfuscator.cpp#L42-L80) if necessary
Hi @theboringhumane thanks for the issue. I'm failing to reproduce the issue with the example code you attached on "running" cloud service.
Tried it in Azure (east-us2 region) and able to connect by just changing the connection string in your example (printing the Result: 1 just fine).
Also I'm able to reproduce the exact error when connecting to service that is stopped (or "idle").
go run main.go
2025/09/29 11:12:04 Ping error: read tcp 192.168.2.20:37948->x.x.x.x:9440: read: connection reset by peer
exit status 1
Can you make sure if your service is up and running?