Skip to content

Commit

Permalink
lightning: fix ipv6 address (#35881) (#35930)
Browse files Browse the repository at this point in the history
close #35880
  • Loading branch information
ti-srebot authored Jul 11, 2022
1 parent d2a264a commit 91f4ca2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions br/pkg/lightning/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -53,8 +55,9 @@ type MySQLConnectParam struct {
}

func (param *MySQLConnectParam) ToDSN() string {
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/?charset=utf8mb4&sql_mode='%s'&maxAllowedPacket=%d&tls=%s",
param.User, param.Password, param.Host, param.Port,
hostPort := net.JoinHostPort(param.Host, strconv.Itoa(param.Port))
dsn := fmt.Sprintf("%s:%s@tcp(%s)/?charset=utf8mb4&sql_mode='%s'&maxAllowedPacket=%d&tls=%s",
param.User, param.Password, hostPort,
param.SQLMode, param.MaxAllowedPacket, param.TLS)

for k, v := range param.Vars {
Expand Down
3 changes: 3 additions & 0 deletions br/pkg/lightning/common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func (s *utilSuite) TestToDSN(c *C) {
},
}
c.Assert(param.ToDSN(), Equals, "root:123456@tcp(127.0.0.1:4000)/?charset=utf8mb4&sql_mode='strict'&maxAllowedPacket=1234&tls=cluster&tidb_distsql_scan_concurrency=1")

param.Host = "::1"
c.Assert(param.ToDSN(), Equals, "root:123456@tcp([::1]:4000)/?charset=utf8mb4&sql_mode='strict'&maxAllowedPacket=1234&tls=cluster&tidb_distsql_scan_concurrency=1")
}

func (s *utilSuite) TestIsContextCanceledError(c *C) {
Expand Down

0 comments on commit 91f4ca2

Please sign in to comment.