Skip to content

Commit

Permalink
fix password escaping bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhichang committed May 20, 2021
1 parent 97d2697 commit 7dc4609
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pool/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
var (
lock sync.Mutex
clusterConn []*ShardConn
dsnTmpl string
dsnSuffix string
)

// ShardConn a datastructure for storing the clickhouse connection
Expand Down Expand Up @@ -86,7 +86,7 @@ func (sc *ShardConn) NextGoodReplica(failedVer int) (db *sql.DB, dbVer int, err
savedNextRep := sc.nextRep
// try all replicas, including the current one
for i := 0; i < len(sc.replicas); i++ {
sc.dsn = fmt.Sprintf(dsnTmpl, sc.replicas[sc.nextRep])
sc.dsn = fmt.Sprintf("tcp://%s", sc.replicas[sc.nextRep]) + dsnSuffix
sc.nextRep = (sc.nextRep + 1) % len(sc.replicas)
sqlDB, err := sql.Open("clickhouse", sc.dsn)
if err != nil {
Expand Down Expand Up @@ -118,13 +118,13 @@ func InitClusterConn(hosts [][]string, port int, db, username, password, dsnPara
freeClusterConn()
// Each shard has a *sql.DB which connects to one replica inside the shard.
// "alt_hosts" tolerates replica single-point-failure. However more flexable switching is needed for some cases for example https://github.com/ClickHouse/ClickHouse/issues/24036.
dsnTmpl = "tcp://%s" + fmt.Sprintf("?database=%s&username=%s&password=%s&block_size=%d",
dsnSuffix = fmt.Sprintf("?database=%s&username=%s&password=%s&block_size=%d",
url.QueryEscape(db), url.QueryEscape(username), url.QueryEscape(password), 2*config.MaxBufferSize)
if dsnParams != "" {
dsnTmpl += "&" + dsnParams
dsnSuffix += "&" + dsnParams
}
if secure {
dsnTmpl += "&secure=true&skip_verify=" + strconv.FormatBool(skipVerify)
dsnSuffix += "&secure=true&skip_verify=" + strconv.FormatBool(skipVerify)
}

for _, replicas := range hosts {
Expand Down

0 comments on commit 7dc4609

Please sign in to comment.