mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 22:06:20 +00:00
consul: ensure connections are properly closed
This commit is contained in:
parent
d1ebf83e39
commit
57cef6e9b1
@ -266,7 +266,10 @@ func (p *ConnPool) getNewConn(addr net.Addr, version int) (*Conn, error) {
|
|||||||
func (p *ConnPool) clearConn(addr net.Addr) {
|
func (p *ConnPool) clearConn(addr net.Addr) {
|
||||||
p.Lock()
|
p.Lock()
|
||||||
defer p.Unlock()
|
defer p.Unlock()
|
||||||
delete(p.pool, addr.String())
|
if conn, ok := p.pool[addr.String()]; ok {
|
||||||
|
conn.Close()
|
||||||
|
delete(p.pool, addr.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// releaseConn is invoked when we are done with a conn to reduce the ref count
|
// releaseConn is invoked when we are done with a conn to reduce the ref count
|
||||||
@ -315,10 +318,8 @@ func (p *ConnPool) RPC(addr net.Addr, version int, method string, args interface
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If its a network error, nuke the connection
|
// Do-not re-use as a pre-caution
|
||||||
if _, ok := err.(net.Error); ok {
|
p.clearConn(addr)
|
||||||
p.clearConn(addr)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("rpc error: %v", err)
|
return fmt.Errorf("rpc error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user