| 465 | } |
| 466 | |
| 467 | func (p *Pool) triggerHealthCheck() { |
| 468 | const healthCheckDelay = 500 * time.Millisecond |
| 469 | |
| 470 | p.healthCheckMu.Lock() |
| 471 | defer p.healthCheckMu.Unlock() |
| 472 | |
| 473 | if p.healthCheckTimer == nil { |
| 474 | // Destroy is asynchronous so we give it time to actually remove itself from |
| 475 | // the pool otherwise we might try to check the pool size too soon |
| 476 | p.healthCheckTimer = time.AfterFunc(healthCheckDelay, func() { |
| 477 | select { |
| 478 | case <-p.closeChan: |
| 479 | case p.healthCheckChan <- struct{}{}: |
| 480 | default: |
| 481 | } |
| 482 | }) |
| 483 | return |
| 484 | } |
| 485 | |
| 486 | p.healthCheckTimer.Reset(healthCheckDelay) |
| 487 | } |
| 488 | |
| 489 | func (p *Pool) backgroundHealthCheck() { |
| 490 | ticker := time.NewTicker(p.healthCheckPeriod) |