consul: do not clear connection cache on RPC errors

This commit is contained in:
Armon Dadgar 2015-04-07 14:17:20 -07:00
parent a817a398dc
commit 32f3d17931
1 changed files with 7 additions and 2 deletions

View File

@ -44,6 +44,11 @@ type StreamClient struct {
client *rpc.Client client *rpc.Client
} }
func (sc *StreamClient) Close() {
sc.stream.Close()
sc.client.Close()
}
// Conn is a pooled connection to a Consul server // Conn is a pooled connection to a Consul server
type Conn struct { type Conn struct {
refCount int32 refCount int32
@ -106,7 +111,7 @@ func (c *Conn) returnClient(client *StreamClient) {
} }
c.clientLock.Unlock() c.clientLock.Unlock()
if !didSave { if !didSave {
client.stream.Close() client.Close()
} }
} }
@ -345,7 +350,7 @@ func (p *ConnPool) RPC(addr net.Addr, version int, method string, args interface
// Make the RPC call // Make the RPC call
err = sc.client.Call(method, args, reply) err = sc.client.Call(method, args, reply)
if err != nil { if err != nil {
p.clearConn(conn) sc.Close()
p.releaseConn(conn) p.releaseConn(conn)
return fmt.Errorf("rpc error: %v", err) return fmt.Errorf("rpc error: %v", err)
} }