Revert "* use defer to avoid tracking lock"

This reverts commit a030abdefc.
This commit causes a connection to be leaked if there is a race with
another concurrent RPC.
pull/707/head
Armon Dadgar 10 years ago
parent 3f23ac2fc7
commit d92e5d37e3

@ -259,28 +259,27 @@ func (p *ConnPool) getNewConn(addr net.Addr, version int) (*Conn, error) {
}
// Wrap the connection
var c *Conn
c := &Conn{
refCount: 1,
addr: addr,
session: session,
clients: list.New(),
lastUsed: time.Now(),
version: version,
pool: p,
}
// Track this connection, handle potential race condition
p.Lock()
defer p.Unlock()
if existing := p.pool[addr.String()]; existing != nil {
c = existing
c.Close()
p.Unlock()
return existing, nil
} else {
c = &Conn{
refCount: 1,
addr: addr,
session: session,
clients: list.New(),
lastUsed: time.Now(),
version: version,
pool: p,
}
p.pool[addr.String()] = c
p.Unlock()
return c, nil
}
return c, nil
}
// clearConn is used to clear any cached connection, potentially in response to an erro

Loading…
Cancel
Save