Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX:when connect to provider fail, will occur panic #1021

Merged
merged 3 commits into from
Jan 30, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix panic when close pool
  • Loading branch information
wenxuwan committed Jan 27, 2021
commit bfa9f5f5168be23d2e205269c764d3860cf4f5df
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use anonymous combination in this case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be will add GetMux function to get lock of client

Copy link
Member

@zouyx zouyx Jan 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- -

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