diff --git a/protocol/dubbo/pool.go b/protocol/dubbo/pool.go index d619a2f8fe78524b3d704cb9de280ebbf534eb12..b5bf040c67c2e0071222466e59db4de67d9e1ca2 100644 --- a/protocol/dubbo/pool.go +++ b/protocol/dubbo/pool.go @@ -289,7 +289,17 @@ func (p *gettyRPCClientPool) close() { } func (p *gettyRPCClientPool) getGettyRpcClient(protocol, addr string) (*gettyRPCClient, error) { - + var ( + conn *gettyRPCClient + err error + ) + if conn, err = p.selectGettyRpcClient(protocol, addr); err == nil && conn == nil { + // create new conn + return newGettyRPCClientConn(p, protocol, addr) + } + return conn, err +} +func (p *gettyRPCClientPool) selectGettyRpcClient(protocol, addr string) (*gettyRPCClient, error) { p.Lock() defer p.Unlock() if p.conns == nil { @@ -308,13 +318,10 @@ func (p *gettyRPCClientPool) getGettyRpcClient(protocol, addr string) (*gettyRPC continue } conn.updateActive(now) //update active time - return conn, nil } - // 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()) -}