Skip to content

Commit

Permalink
Merge pull request #7045 from hashicorp/b-rpc-fixes
Browse files Browse the repository at this point in the history
Some fixes to connection pooling
  • Loading branch information
Mahmood Ali committed Feb 3, 2020
2 parents 7f43161 + 3bfc7d1 commit e8136c0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions helper/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
if err != nil {
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)

// If the error is an RPC Coded error
Expand Down

0 comments on commit e8136c0

Please sign in to comment.