From 041cbd4a63c040cb199b5ca136841d21ccbe8943 Mon Sep 17 00:00:00 2001 From: wangwx Date: Tue, 26 Jan 2021 22:13:21 +0800 Subject: [PATCH 1/2] fix panic when connect to provider fail --- protocol/protocolwrapper/protocol_filter_wrapper.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/protocol/protocolwrapper/protocol_filter_wrapper.go b/protocol/protocolwrapper/protocol_filter_wrapper.go index 679036f20e..448bd6f5a9 100644 --- a/protocol/protocolwrapper/protocol_filter_wrapper.go +++ b/protocol/protocolwrapper/protocol_filter_wrapper.go @@ -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. From 6f5d9dc223ee36e58aabf77d77d43ac31c591576 Mon Sep 17 00:00:00 2001 From: wangwx Date: Wed, 27 Jan 2021 10:51:04 +0800 Subject: [PATCH 2/2] fix panic when close pool --- remoting/getty/getty_client.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/remoting/getty/getty_client.go b/remoting/getty/getty_client.go index 57221cc6d7..414f045d1e 100644 --- a/remoting/getty/getty_client.go +++ b/remoting/getty/getty_client.go @@ -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 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)