Skip to content

Commit

Permalink
fix data race rethinkdb#488
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Manley committed Sep 16, 2020
1 parent 3d6444f commit 59b3add
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (p *Pool) Close() error {
}

func (p *Pool) conn() (*Connection, error) {
p.mu.Lock()
defer p.mu.Unlock()

if atomic.LoadInt32(&p.closed) == poolIsClosed {
return nil, errPoolClosed
}
Expand All @@ -120,9 +123,6 @@ func (p *Pool) conn() (*Connection, error) {
var err error

if p.conns[pos] == nil {
p.mu.Lock()
defer p.mu.Unlock()

if p.conns[pos] == nil {
p.conns[pos], err = p.connFactory(p.host.String(), p.opts)
if err != nil {
Expand All @@ -131,9 +131,6 @@ func (p *Pool) conn() (*Connection, error) {
}
} else if p.conns[pos].isBad() {
// connBad connection needs to be reconnected
p.mu.Lock()
defer p.mu.Unlock()

p.conns[pos], err = p.connFactory(p.host.String(), p.opts)
if err != nil {
return nil, err
Expand Down

0 comments on commit 59b3add

Please sign in to comment.