fix rpc conn close

This commit is contained in:
Ulric Qin 2020-04-09 00:31:48 +08:00
parent 761c0fae25
commit d4b24ed573
1 changed files with 7 additions and 7 deletions

View File

@ -78,14 +78,19 @@ func rpcCall(addr string, items []*dataobj.MetricValue) (dataobj.TransferResp, e
var reply dataobj.TransferResp
var err error
affected := false
client := rpcClients.Get(addr)
if client == nil {
client, err = rpcClient(addr)
if err != nil {
return reply, err
} else {
affected = rpcClients.Put(addr, client)
affected := rpcClients.Put(addr, client)
if !affected {
defer func() {
// 我尝试把自己这个client塞进map失败说明已经有一个client塞进去了那我自己用完了就关闭
client.Close()
}()
}
}
}
@ -111,11 +116,6 @@ func rpcCall(addr string, items []*dataobj.MetricValue) (dataobj.TransferResp, e
}
}
if !affected {
// 我尝试把自己这个client塞进map失败说明已经有一个client塞进去了那我自己用完了就关闭
client.Close()
}
return reply, nil
}