修复map加锁无效

pull/21/merge v1.0
ouqiang 2017-06-26 18:07:56 +08:00
parent 3e8c3a236e
commit 3d61c7694b
1 changed files with 3 additions and 1 deletions

View File

@ -32,8 +32,8 @@ type GRPCPool struct {
func (p *GRPCPool) Get(addr string) (*grpc.ClientConn, error) { func (p *GRPCPool) Get(addr string) (*grpc.ClientConn, error) {
p.RLock() p.RLock()
defer p.RUnlock()
pool, ok := p.conns[addr] pool, ok := p.conns[addr]
p.RUnlock()
if !ok { if !ok {
err := p.newCommonPool(addr) err := p.newCommonPool(addr)
if err != nil { if err != nil {
@ -41,7 +41,9 @@ func (p *GRPCPool) Get(addr string) (*grpc.ClientConn, error) {
} }
} }
p.RLock()
pool = p.conns[addr] pool = p.conns[addr]
p.RUnlock()
conn, err := pool.Get() conn, err := pool.Get()
if err != nil { if err != nil {
return nil, err return nil, err