Skip to content

Commit

Permalink
Merge pull request #286 from pantianying/develop_gettyPool_lock
Browse files Browse the repository at this point in the history
change the position of the lock
  • Loading branch information
hxmhlt authored Dec 22, 2019
2 parents 9604e7a + e6e0e14 commit 8d46ac0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
17 changes: 12 additions & 5 deletions protocol/dubbo/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions registry/protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions registry/protocol/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 comments on commit 8d46ac0

Please sign in to comment.