Skip to content

Commit

Permalink
fix panic when close pool
Browse files Browse the repository at this point in the history
  • Loading branch information
wenxuwan committed Jan 27, 2021
1 parent 9c3ee3a commit bfa9f5f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions remoting/getty/getty_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package getty

import (
"math/rand"
"sync"
"time"
)

Expand Down Expand Up @@ -116,6 +117,7 @@ type Client struct {
addr string
opts Options
conf ClientConfig
mux sync.RWMutex
pool *gettyRPCClientPool
codec remoting.Codec
ExchangeClient *remoting.ExchangeClient
Expand Down Expand Up @@ -161,10 +163,13 @@ func (c *Client) Connect(url *common.URL) error {

// close network connection
func (c *Client) Close() {
if c.pool != nil {
c.pool.close()
}
c.mux.Lock()
p := c.pool
c.pool = nil
c.mux.Unlock()
if p != nil {
p.close()
}
}

// send request
Expand Down Expand Up @@ -204,6 +209,11 @@ func (c *Client) IsAvailable() bool {
}

func (c *Client) selectSession(addr string) (*gettyRPCClient, getty.Session, error) {
c.mux.RLock()
defer c.mux.RUnlock()
if c.pool == nil {
return nil, nil, perrors.New("client pool have been closed")
}
rpcClient, err := c.pool.getGettyRpcClient(addr)
if err != nil {
return nil, nil, perrors.WithStack(err)
Expand Down

0 comments on commit bfa9f5f

Please sign in to comment.