Merge pull request #7045 from hashicorp/b-rpc-fixes

Some fixes to connection pooling
This commit is contained in:
Mahmood Ali 2020-02-03 13:10:15 -05:00 committed by GitHub
commit 06a283ea93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/hashicorp/consul/lib"
hclog "github.com/hashicorp/go-hclog" hclog "github.com/hashicorp/go-hclog"
msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc"
"github.com/hashicorp/nomad/helper/tlsutil" "github.com/hashicorp/nomad/helper/tlsutil"
@ -36,6 +37,7 @@ type StreamClient struct {
func (sc *StreamClient) Close() { func (sc *StreamClient) Close() {
sc.stream.Close() sc.stream.Close()
sc.codec.Close()
} }
// Conn is a pooled connection to a Nomad server // Conn is a pooled connection to a Nomad server
@ -425,6 +427,14 @@ func (p *ConnPool) RPC(region string, addr net.Addr, version int, method string,
err = msgpackrpc.CallWithCodec(sc.codec, method, args, reply) err = msgpackrpc.CallWithCodec(sc.codec, method, args, reply)
if err != nil { if err != nil {
sc.Close() sc.Close()
// 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)
}
p.releaseConn(conn) p.releaseConn(conn)
// If the error is an RPC Coded error // If the error is an RPC Coded error