Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: fix ipv6 host address #43815

Merged
merged 2 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion br/pkg/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"net"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -387,7 +388,7 @@ func handleTiKVAddress(store *metapb.Store, httpPrefix string) (*url.URL, error)
// but in sometimes we may not get the correct status address from PD.
if statusUrl.Hostname() != nodeUrl.Hostname() {
// if not matched, we use the address as default, but change the port
addr.Host = nodeUrl.Hostname() + ":" + statusUrl.Port()
addr.Host = net.JoinHostPort(nodeUrl.Hostname(), statusUrl.Port())
log.Warn("store address and status address mismatch the host, we will use the store address as hostname",
zap.Uint64("store", store.Id),
zap.String("status address", statusAddr),
Expand Down
14 changes: 7 additions & 7 deletions ddl/ddl_tiflash_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"net"
"strconv"
"time"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -263,9 +264,8 @@ func getTiflashHTTPAddr(host string, statusAddr string) (string, error) {
if !ok {
return "", errors.New("Error json")
}
port := int(port64)

addr := fmt.Sprintf("%v:%v", host, port)
addr := net.JoinHostPort(host, strconv.FormatUint(uint64(port64), 10))
return addr, nil
}

Expand Down Expand Up @@ -294,11 +294,11 @@ func LoadTiFlashReplicaInfo(tblInfo *model.TableInfo, tableList *[]TiFlashReplic

// UpdateTiFlashHTTPAddress report TiFlash's StatusAddress's port to Pd's etcd.
func (d *ddl) UpdateTiFlashHTTPAddress(store *helper.StoreStat) error {
addrAndPort := strings.Split(store.Store.StatusAddress, ":")
if len(addrAndPort) < 2 {
return errors.New("Can't get TiFlash Address from PD")
host, _, err := net.SplitHostPort(store.Store.StatusAddress)
if err != nil {
return errors.Trace(err)
}
httpAddr, err := getTiflashHTTPAddr(addrAndPort[0], store.Store.StatusAddress)
httpAddr, err := getTiflashHTTPAddr(host, store.Store.StatusAddress)
if err != nil {
return errors.Trace(err)
}
Expand Down
3 changes: 2 additions & 1 deletion infoschema/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package infoschema

import (
"net"
"strconv"
"strings"

Expand Down Expand Up @@ -148,7 +149,7 @@ func GetInstanceAddr(ctx sessionctx.Context) (string, error) {
if err != nil {
return "", err
}
addr := serverInfo.IP + ":" + strconv.FormatUint(uint64(serverInfo.StatusPort), 10)
addr := net.JoinHostPort(serverInfo.IP, strconv.FormatUint(uint64(serverInfo.StatusPort), 10))
if sem.IsEnabled() {
checker := privilege.GetPrivilegeManager(ctx)
if checker == nil || !checker.RequestDynamicVerification(ctx.GetSessionVars().ActiveRoles, "RESTRICTED_TABLES_ADMIN", false) {
Expand Down
4 changes: 3 additions & 1 deletion privilege/privileges/ldap/ldap_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"net"
"os"
"strconv"
"sync"

"github.com/go-ldap/ldap/v3"
Expand Down Expand Up @@ -119,7 +121,7 @@ func (impl *ldapAuthImpl) initializeCAPool() error {
}

func (impl *ldapAuthImpl) connectionFactory() (pools.Resource, error) {
address := fmt.Sprintf("%s:%d", impl.ldapServerHost, impl.ldapServerPort)
address := net.JoinHostPort(impl.ldapServerHost, strconv.FormatUint(uint64(impl.ldapServerPort), 10))

// It's fine to load these two TLS configurations one-by-one (but not guarded by a single lock), because there isn't
// a way to set two variables atomically.
Expand Down
3 changes: 2 additions & 1 deletion store/copr/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math"
"net"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -576,7 +577,7 @@ func buildTiDBMemCopTasks(ranges *KeyRanges, req *kv.Request) ([]*copTask, error
continue
}

addr := ser.IP + ":" + strconv.FormatUint(uint64(ser.StatusPort), 10)
addr := net.JoinHostPort(ser.IP, strconv.FormatUint(uint64(ser.StatusPort), 10))
tasks = append(tasks, &copTask{
ranges: ranges,
respChan: make(chan *copResponse, 2),
Expand Down
3 changes: 2 additions & 1 deletion util/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/tls"
"errors"
"fmt"
"net"
"strings"
"sync/atomic"
"time"
Expand Down Expand Up @@ -85,7 +86,7 @@ func (pi *ProcessInfo) ToRowForShow(full bool) []interface{} {
}
var host string
if pi.Port != "" {
host = fmt.Sprintf("%s:%s", pi.Host, pi.Port)
host = net.JoinHostPort(pi.Host, pi.Port)
} else {
host = pi.Host
}
Expand Down