Skip to content

Commit

Permalink
Disable sticky session on direct sentries
Browse files Browse the repository at this point in the history
  • Loading branch information
nhannamsiu committed Apr 21, 2022
1 parent fd1190c commit 0ffa7b1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions client/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type chainClient struct {
accSeq uint64

sessionCookie string
sessionEnabled bool

txClient txtypes.ServiceClient
authQueryClient authtypes.QueryClient
Expand Down Expand Up @@ -124,10 +125,12 @@ func NewChainClient(

var conn *grpc.ClientConn
var err error
stickySessionEnabled := true
if opts.TLSCert != nil {
conn, err = grpc.Dial(protoAddr, grpc.WithTransportCredentials(opts.TLSCert), grpc.WithContextDialer(common.DialerFunc))
} else {
conn, err = grpc.Dial(protoAddr, grpc.WithInsecure(), grpc.WithContextDialer(common.DialerFunc))
stickySessionEnabled = false
}
if err != nil {
err := errors.Wrapf(err, "failed to connect to the gRPC: %s", protoAddr)
Expand All @@ -151,6 +154,8 @@ func NewChainClient(
msgC: make(chan sdk.Msg, msgCommitBatchSizeLimit),
doneC: make(chan bool, 1),

sessionEnabled: stickySessionEnabled,

txClient: txtypes.NewServiceClient(conn),
authQueryClient: authtypes.NewQueryClient(conn),
exchangeQueryClient: exchangetypes.NewQueryClient(conn),
Expand Down Expand Up @@ -239,6 +244,9 @@ func (c *chainClient) getAccSeq() uint64 {
}

func (c *chainClient) setCookie(metadata metadata.MD) {
if !c.sessionEnabled {
return
}
md := metadata.Get("set-cookie")
if len(md) > 0 {
c.sessionCookie = md[0]
Expand All @@ -247,6 +255,9 @@ func (c *chainClient) setCookie(metadata metadata.MD) {

func (c *chainClient) getCookie(ctx context.Context) context.Context {
md := metadata.Pairs("cookie", c.sessionCookie)
if !c.sessionEnabled {
return metadata.NewOutgoingContext(ctx, md)
}

// borrow http request to parse cookie
header := http.Header{}
Expand Down

0 comments on commit 0ffa7b1

Please sign in to comment.