Skip to content
Snippets Groups Projects
Unverified Commit 8d46ac0f authored by vito.he's avatar vito.he Committed by GitHub
Browse files

Merge pull request #286 from pantianying/develop_gettyPool_lock

change the position of the lock
parents 9604e7ac e6e0e14f
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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 {
......
......@@ -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())
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment