Skip to content

Commit

Permalink
fix rpc conn close
Browse files Browse the repository at this point in the history
  • Loading branch information
UlricQin committed Apr 8, 2020
1 parent 761c0fa commit d4b24ed
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/modules/collector/sys/funcs/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
}
}
}

Expand All @@ -111,11 +116,6 @@ func rpcCall(addr string, items []*dataobj.MetricValue) (dataobj.TransferResp, e
}
}

if !affected {
// 我尝试把自己这个client塞进map失败,说明已经有一个client塞进去了,那我自己用完了就关闭
client.Close()
}

return reply, nil
}

Expand Down

0 comments on commit d4b24ed

Please sign in to comment.