From b0d9e8dd87cc068b60e057f28d52b006ac5bb3fe Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Wed, 25 Oct 2017 00:46:37 -0500 Subject: [PATCH] tidb-server: fix binlog client is not initialized correctly (#4887) --- tidb-server/main.go | 3 +-- tidb.go | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tidb-server/main.go b/tidb-server/main.go index 36617a093a..ff329fc816 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -166,8 +166,7 @@ func setupBinlogClient() { dialerOpt := grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { return net.DialTimeout("unix", addr, timeout) }) - var clientConn *grpc.ClientConn - err := tidb.DialPumpClientWithRetry(cfg.BinlogSocket, clientConn, util.DefaultMaxRetries, dialerOpt) + clientConn, err := tidb.DialPumpClientWithRetry(cfg.BinlogSocket, util.DefaultMaxRetries, dialerOpt) terror.MustNil(err) binloginfo.SetPumpClient(binlog.NewPumpClient(clientConn)) log.Infof("created binlog client at %s", cfg.BinlogSocket) diff --git a/tidb.go b/tidb.go index 3ed05baf61..b0543c7fd2 100644 --- a/tidb.go +++ b/tidb.go @@ -258,8 +258,9 @@ func newStoreWithRetry(path string, maxRetries int) (kv.Storage, error) { // DialPumpClientWithRetry tries to dial to binlogSocket, // if any error happens, it will try to re-dial, // or return this error when timeout. -func DialPumpClientWithRetry(binlogSocket string, clientCon *grpc.ClientConn, maxRetries int, dialerOpt grpc.DialOption) error { - return util.RunWithRetry(maxRetries, util.RetryInterval, func() (bool, error) { +func DialPumpClientWithRetry(binlogSocket string, maxRetries int, dialerOpt grpc.DialOption) (*grpc.ClientConn, error) { + var clientCon *grpc.ClientConn + err := util.RunWithRetry(maxRetries, util.RetryInterval, func() (bool, error) { log.Infof("setup binlog client") var err error clientCon, err = grpc.Dial(binlogSocket, grpc.WithInsecure(), dialerOpt) @@ -268,6 +269,7 @@ func DialPumpClientWithRetry(binlogSocket string, clientCon *grpc.ClientConn, ma } return true, errors.Trace(err) }) + return clientCon, errors.Trace(err) } var queryStmtTable = []string{"explain", "select", "show", "execute", "describe", "desc", "admin"}