()
| 542 | } |
| 543 | |
| 544 | func (p *ConnPool) addIdleConn() error { |
| 545 | // Do not apply DialTimeout via context here; dialConn applies DialTimeout per attempt. |
| 546 | cn, err := p.dialConn(context.Background(), true) |
| 547 | if err != nil { |
| 548 | return err |
| 549 | } |
| 550 | |
| 551 | // NOTE: Connection is in CREATED state and will be initialized by redis.go:initConn() |
| 552 | // when first acquired from the pool. Do NOT transition to IDLE here - that happens |
| 553 | // after initialization completes. |
| 554 | |
| 555 | p.connsMu.Lock() |
| 556 | defer p.connsMu.Unlock() |
| 557 | |
| 558 | // It is not allowed to add new connections to the closed connection pool. |
| 559 | if p.closed() { |
| 560 | _ = cn.Close() |
| 561 | return ErrClosed |
| 562 | } |
| 563 | |
| 564 | p.conns[cn.GetID()] = cn |
| 565 | p.idleConns = append(p.idleConns, cn) |
| 566 | |
| 567 | // Record connection count increment (new idle connection from min-idle prewarm) |
| 568 | if cb := getMetricConnectionCountCallback(); cb != nil { |
| 569 | cb(context.Background(), 1, cn, "idle", false) |
| 570 | } |
| 571 | |
| 572 | return nil |
| 573 | } |
| 574 | |
| 575 | // NewConn creates a new connection and returns it to the user. |
| 576 | // This will still obey MaxActiveConns but will not include it in the pool and won't increase the pool size. |
no test coverage detected