-
Notifications
You must be signed in to change notification settings - Fork 929
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ package getty | |
|
||
import ( | ||
"math/rand" | ||
"sync" | ||
"time" | ||
) | ||
|
||
|
@@ -116,6 +117,7 @@ type Client struct { | |
addr string | ||
opts Options | ||
conf ClientConfig | ||
mux sync.RWMutex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you use anonymous combination in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may be will add GetMux function to get lock of client There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
pool *gettyRPCClientPool | ||
codec remoting.Codec | ||
ExchangeClient *remoting.ExchangeClient | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'go mod tidy'