Skip to content

Commit

Permalink
Merge pull request #1021 from wenxuwan/newestVersion
Browse files Browse the repository at this point in the history
FIX:when connect to provider fail, will occur panic
  • Loading branch information
AlexStocks committed Jan 30, 2021
2 parents d2a40aa + bfa9f5f commit 5c76040
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion protocol/protocolwrapper/protocol_filter_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func (pfw *ProtocolFilterWrapper) Refer(url *common.URL) protocol.Invoker {
if pfw.protocol == nil {
pfw.protocol = extension.GetProtocol(url.Protocol)
}
return buildInvokerChain(pfw.protocol.Refer(url), constant.REFERENCE_FILTER_KEY)
invoker := pfw.protocol.Refer(url)
if invoker == nil {
return nil
}
return buildInvokerChain(invoker, constant.REFERENCE_FILTER_KEY)
}

// Destroy will destroy all invoker and exporter.
Expand Down
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 5c76040

Please sign in to comment.