Skip to content

Commit

Permalink
Merge pull request apache#332 from brandscreen/master
Browse files Browse the repository at this point in the history
Wait until we're done connecting before returning from fillPool
  • Loading branch information
0x6e6562 committed Mar 17, 2015
2 parents 1a204ef + ed80a37 commit af32d99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ Ashwin Purohit <purohit@gmail.com>
Dan Kinder <dkinder.is.me@gmail.com>
Oliver Beattie <oliver@obeattie.com>
Justin Corpron <justin@retailnext.com>
Miles Delahunty <miles.delahunty@gmail.com>
6 changes: 6 additions & 0 deletions connectionpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (c *SimplePool) fillPool() {
c.hostMu.RLock()

//Walk through list of defined hosts
var wg sync.WaitGroup
for host := range c.hosts {
addr := JoinHostPort(host, c.cfg.Port)

Expand All @@ -251,14 +252,19 @@ func (c *SimplePool) fillPool() {

//This is reached if the host is responsive and needs more connections
//Create connections for host synchronously to mitigate flooding the host.
wg.Add(1)
go func(a string, conns int) {
defer wg.Done()
for ; conns < c.cfg.NumConns; conns++ {
c.connect(a)
}
}(addr, numConns)
}

c.hostMu.RUnlock()

//Wait until we're finished connecting to each host before returning
wg.Wait()
}

// Should only be called if c.mu is locked
Expand Down

0 comments on commit af32d99

Please sign in to comment.