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 5227cf1 commit aec5225
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions client/xclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,32 +246,31 @@ func filterByStateAndGroup(group string, servers map[string]string) {
func (c *xClient) selectClient(ctx context.Context, servicePath, serviceMethod string, args interface{}) (string, RPCClient, error) {
c.mu.Lock()
if c.option.Sticky && c.stickyRPCClient != nil {
stickyK := c.stickyK
stickyRPCClient := c.stickyRPCClient
c.mu.Unlock()
return stickyK, stickyRPCClient, nil
return c.stickyK, c.stickyRPCClient, nil
}

fn := c.selector.Select
if c.Plugins != nil {
fn = c.Plugins.DoWrapSelect(fn)
}
k := fn(ctx, servicePath, serviceMethod, args)
c.mu.Unlock()

if k == "" {
c.mu.Unlock()
return "", nil, ErrXClientNoServer
}

client, err := c.getCachedClient(k, servicePath, serviceMethod, args)

c.mu.Lock()
if c.option.Sticky && client != nil {
c.mu.Lock()
safeCloseClient(c.stickyRPCClient)

c.stickyK = k
c.stickyRPCClient = client
c.mu.Unlock()
}
c.mu.Unlock()

return k, client, err
}
Expand Down

0 comments on commit aec5225

Please sign in to comment.