diff --git a/protocol/dubbo/pool.go b/protocol/dubbo/pool.go index 0c4e74ae71bdf953f2c8c957d0e66f2267115a25..6a5a62bd96be8ab8dc92c155ebc07ca0d37a8bb6 100644 --- a/protocol/dubbo/pool.go +++ b/protocol/dubbo/pool.go @@ -289,10 +289,18 @@ func (p *gettyRPCClientPool) close() { } func (p *gettyRPCClientPool) getGettyRpcClient(protocol, addr string) (*gettyRPCClient, error) { - + if conn, err := p.selectGettyRpcClient(protocol, addr); err != nil { + return nil, err + } else if conn != nil { + return conn, nil + } + // create new conn + return newGettyRPCClientConn(p, protocol, addr) +} +func (p *gettyRPCClientPool) selectGettyRpcClient(protocol, addr string) (*gettyRPCClient, error) { p.Lock() + defer p.Unlock() if p.conns == nil { - p.Unlock() return nil, errClientPoolClosed } @@ -308,14 +316,10 @@ func (p *gettyRPCClientPool) getGettyRpcClient(protocol, addr string) (*gettyRPC continue } conn.updateActive(now) //update active time - p.Unlock() return conn, nil } - p.Unlock() - // create new conn - return newGettyRPCClientConn(p, protocol, addr) + return nil, nil } - func (p *gettyRPCClientPool) release(conn *gettyRPCClient, err error) { if conn == nil || conn.getActive() == 0 { return diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go index ffdb2753d6bfa0712b8fb9c962c8433a5c281083..534a4b945965f332e49ff343557fa20355921454 100644 --- a/registry/protocol/protocol.go +++ b/registry/protocol/protocol.go @@ -338,10 +338,10 @@ func setProviderUrl(regURL *common.URL, providerURL *common.URL) { } func GetProtocol() protocol.Protocol { - if regProtocol == nil { - regProtocol = newRegistryProtocol() + if regProtocol != nil { + return regProtocol } - return regProtocol + return newRegistryProtocol() } type wrappedInvoker struct { diff --git a/registry/protocol/protocol_test.go b/registry/protocol/protocol_test.go index 761d14006680a3e0f3a111458d32155b19c26968..0c19da59df6e4fd2f663f9e8d541165fe26c3ffa 100644 --- a/registry/protocol/protocol_test.go +++ b/registry/protocol/protocol_test.go @@ -291,8 +291,3 @@ func TestExportWithApplicationConfig(t *testing.T) { v2, _ := regProtocol.bounds.Load(getCacheKey(newUrl)) assert.NotNil(t, v2) } - -func TestGetProtocol(t *testing.T) { - singleton := GetProtocol() - assert.True(t, singleton == GetProtocol()) -}