Skip to content
Snippets Groups Projects
Commit 16aff1fb authored by pantianying's avatar pantianying
Browse files

fix bug for reverseRegistryProtocol

fix travis-ci problem

change lock position

change lock position
parent d1da7ba6
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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