mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 13:55:55 +00:00
Revert "* use defer to avoid tracking lock"
This reverts commit a030abdefc54470394a2a44008e02f3b3d0510ec. This commit causes a connection to be leaked if there is a race with another concurrent RPC.
This commit is contained in:
parent
3f23ac2fc7
commit
d92e5d37e3
@ -259,16 +259,7 @@ func (p *ConnPool) getNewConn(addr net.Addr, version int) (*Conn, error) {
|
||||
}
|
||||
|
||||
// Wrap the connection
|
||||
var c *Conn
|
||||
|
||||
// Track this connection, handle potential race condition
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
if existing := p.pool[addr.String()]; existing != nil {
|
||||
c = existing
|
||||
} else {
|
||||
c = &Conn{
|
||||
c := &Conn{
|
||||
refCount: 1,
|
||||
addr: addr,
|
||||
session: session,
|
||||
@ -277,11 +268,19 @@ func (p *ConnPool) getNewConn(addr net.Addr, version int) (*Conn, error) {
|
||||
version: version,
|
||||
pool: p,
|
||||
}
|
||||
p.pool[addr.String()] = c
|
||||
}
|
||||
|
||||
// Track this connection, handle potential race condition
|
||||
p.Lock()
|
||||
if existing := p.pool[addr.String()]; existing != nil {
|
||||
c.Close()
|
||||
p.Unlock()
|
||||
return existing, nil
|
||||
} else {
|
||||
p.pool[addr.String()] = c
|
||||
p.Unlock()
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
|
||||
// clearConn is used to clear any cached connection, potentially in response to an erro
|
||||
func (p *ConnPool) clearConn(conn *Conn) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user