Skip to content

Commit

Permalink
Merge pull request #44 from golift/dn2_crash_fix
Browse files Browse the repository at this point in the history
Fix crash in PoolStats
  • Loading branch information
davidnewhall authored Apr 18, 2024
2 parents df98c54 + 2534069 commit 31eda5f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ func (c *Client) PoolStats() map[string]*PoolSize {
sizes := map[string]*PoolSize{}

for socket, pool := range c.pools {
sizes[socket] = pool.Size()
if pool.shutdown {
// Use internal method on dead pools.
sizes[socket] = pool.size()
} else {
sizes[socket] = pool.Size()
}
}

return sizes
Expand Down
6 changes: 5 additions & 1 deletion client/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (p *Pool) connector(ctx context.Context, now time.Time) {

func (p *Pool) fillConnectionPool(ctx context.Context, now time.Time, toCreate int) {
if p.client.RoundRobinConfig != nil {
if toCreate == 0 {
if toCreate == 0 || len(p.connections) > 0 {
// Keep this up to date, or the logic will skip to the next server prematurely.
p.client.lastConn = now
} else if now.Sub(p.client.lastConn) > p.client.RetryInterval {
Expand Down Expand Up @@ -211,6 +211,10 @@ func (p *Pool) size() *PoolSize {
poolSize.LastConn = p.client.lastConn
}

if p.shutdown {
return poolSize
}

for _, connection := range p.connections {
switch connection.Status() {
case CONNECTING:
Expand Down

0 comments on commit 31eda5f

Please sign in to comment.