Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao committed Aug 20, 2021
1 parent 9bdf667 commit 12bcebc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 3 additions & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ func (c *RPCClient) getConnArray(addr string, enableBatch bool, opt ...func(cfg
}
array, ok := c.conns[addr]
c.RUnlock()
if !ok {
// An idle connArray will not change to active again, this avoid the race condition
// that recycling idle connection close an active connection unexpectedly (idle -> active).
if !ok || array.isIdle() {
var err error
array, err = c.createConnArray(addr, enableBatch, opt...)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions internal/client/client_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,6 @@ func (c *RPCClient) recycleIdleConnArray() {
}
c.Unlock()

// NOTE, There is a risk that an idle connection become active again, and here is
// a race condition someone is using the connection and it's closed here.
if conn != nil {
conn.Close()
}
Expand Down

0 comments on commit 12bcebc

Please sign in to comment.