tikv / pd

Placement driver for TiKV
Apache License 2.0
1.05k stars 721 forks source link

close pd client meet `context canceled` error #1134

Closed WangXiangUSTC closed 6 years ago

WangXiangUSTC commented 6 years ago

In tidb-binlog, we will connect to pd to get some information, it always get context canceled error when close pd client, the logs are below:

time="2018-07-03T13:24:37+08:00" level=info msg="[pd] create pd client with endpoints [http://127.0.0.1:2379]"
time="2018-07-03T13:24:37+08:00" level=info msg="[pd] leader switches to: http://192.168.31.246:2379, previous: "
time="2018-07-03T13:24:37+08:00" level=info msg="[pd] init cluster id 6572000418809746278"
2018/07/03 13:24:37 server.go:81: [info] clusterID of drainer server is 6572000418809746278
time="2018-07-03T13:24:37+08:00" level=error msg="[pd] create tso stream error: rpc error: code = Canceled desc = context canceled"

This error dosen't matter, but may make some confused to users, can we refine the code to avoid this error?

the pd version I use: version: eed819b6999186a4bf2d25255f8d61b371a450d6

disksing commented 6 years ago

Hi @WangXiangUSTC , do you close the pd client right after done use of it?

WangXiangUSTC commented 6 years ago

the code like this:

    pdCli, err := getPdClient(cfg)
    if err != nil {
        return nil, errors.Trace(err)
    }

    clusterID = pdCli.GetClusterID(ctx)
    pdCli.Close()

@disksing

disksing commented 6 years ago

hi @WangXiangUSTC , I have sent a PR to fix it. If it is convenient, you can try it with the branch of PR in advance.

WangXiangUSTC commented 6 years ago

@disksing Thanks!