Skip to content

Commit

Permalink
close the sticky client
Browse files Browse the repository at this point in the history
  • Loading branch information
smallnest committed Mar 25, 2024
1 parent 5015f0a commit 5227cf1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client/xclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (c *xClient) selectClient(ctx context.Context, servicePath, serviceMethod s

c.mu.Lock()
if c.option.Sticky && client != nil {
safeCloseClient(c.stickyRPCClient)
c.stickyK = k
c.stickyRPCClient = client
}
Expand All @@ -275,6 +276,18 @@ func (c *xClient) selectClient(ctx context.Context, servicePath, serviceMethod s
return k, client, err
}

func safeCloseClient(client RPCClient) {
if client == nil {
return
}

defer func() {
_ = recover()
}()

client.Close()
}

func (c *xClient) getCachedClient(k string, servicePath, serviceMethod string, args interface{}) (RPCClient, error) {
// TODO: improve the lock
var client RPCClient
Expand Down

0 comments on commit 5227cf1

Please sign in to comment.