Commit 82b8e086 authored by Mahmood Ali's avatar Mahmood Ali
Browse files

Some fixes to connection pooling

Pick up some fixes from Consul:

* If a stream returns an EOF error, clear session from cache/pool and start a
new one.
* Close the codec when closing StreamClient
Showing with 9 additions and 0 deletions
+9 -0
......@@ -11,6 +11,7 @@ import (
"sync/atomic"
"time"
"github.com/hashicorp/consul/lib"
hclog "github.com/hashicorp/go-hclog"
msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc"
"github.com/hashicorp/nomad/helper/tlsutil"
......@@ -36,6 +37,7 @@ type StreamClient struct {
func (sc *StreamClient) Close() {
sc.stream.Close()
sc.codec.Close()
}
// Conn is a pooled connection to a Nomad server
......@@ -427,6 +429,13 @@ func (p *ConnPool) RPC(region string, addr net.Addr, version int, method string,
sc.Close()
p.releaseConn(conn)
// If we read EOF, the session is toast. Clear it and open a
// new session next time
// See https://github.com/hashicorp/consul/blob/v1.6.3/agent/pool/pool.go#L471-L477
if lib.IsErrEOF(err) {
p.clearConn(conn)
}
// If the error is an RPC Coded error
// return the coded error without wrapping
if structs.IsErrRPCCoded(err) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment