func (p *pool) makeNewConnection(ctx context.Context) (*connection, string, error) {
	c, err := newConnection(ctx, p.address, p.opts...)
	if err != nil {
		return nil, event.ReasonConnectionErrored, err
	}

	c.pool = p
	c.poolID = atomic.AddUint64(&p.nextid, 1)
	c.generation = atomic.LoadUint64(&p.generation)

	if p.monitor != nil {
		p.monitor.Event(&event.PoolEvent{
			Type:         event.ConnectionCreated,
			Address:      p.address.String(),
			ConnectionID: c.poolID,
		})
	}

	if atomic.LoadInt32(&p.connected) != connected {
		if p.monitor != nil {
			p.monitor.Event(&event.PoolEvent{
				Type:         event.ConnectionClosed,
				Address:      p.address.String(),
				ConnectionID: c.poolID,
				Reason:       event.ReasonPoolClosed,
			})
		}
		_ = p.closeConnection(c) // The pool is disconnected or disconnecting, ignore the error from closing the connection.
		return nil, event.ReasonPoolClosed, ErrPoolDisconnected
	}

	p.Lock()
	p.opened[c.poolID] = c
	p.Unlock()

	return c, "", nil

}
// requires that p be locked
requires that p be locked
// requires that p be locked
func (p *pool) makeNewConnection(ctx context.Context) (*connection, string, error) {
	c, err := newConnection(ctx, p.address, p.opts...)
	if err != nil {
		return nil, event.ReasonConnectionErrored, err
	}
	c.pool = p
	c.poolID = atomic.AddUint64(&p.nextid, 1)
	c.generation = atomic.LoadUint64(&p.generation)
	if p.monitor != nil {
		p.monitor.Event(&event.PoolEvent{
			Type:         event.ConnectionCreated,
			Address:      p.address.String(),
			ConnectionID: c.poolID,
		})
	}
	if atomic.LoadInt32(&p.connected) != connected {
		if p.monitor != nil {
			p.monitor.Event(&event.PoolEvent{
				Type:         event.ConnectionClosed,
				Address:      p.address.String(),
				ConnectionID: c.poolID,
				Reason:       event.ReasonPoolClosed,
			})
		}
		_ = p.closeConnection(c) 
		return nil, event.ReasonPoolClosed, ErrPoolDisconnected
	}
	p.Lock()
	p.opened[c.poolID] = c
	p.Unlock()
	return c, "", nil
}
func ( p * pool ) makeNewConnection ( ctx context . Context ) ( * connection , string , error ) { c , err := newConnection ( ctx , p . address , p . opts ... ) if err != nil { return nil , event . ReasonConnectionErrored , err } c . pool = p c . poolID = atomic . AddUint64 ( & p . nextid , 1 ) c . generation = atomic . LoadUint64 ( & p . generation ) if p . monitor != nil { p . monitor . Event ( & event . PoolEvent { Type : event . ConnectionCreated , Address : p . address . String ( ) , ConnectionID : c . poolID , } ) } if atomic . LoadInt32 ( & p . connected ) != connected { if p . monitor != nil { p . monitor . Event ( & event . PoolEvent { Type : event . ConnectionClosed , Address : p . address . String ( ) , ConnectionID : c . poolID , Reason : event . ReasonPoolClosed , } ) } _ = p . closeConnection ( c ) return nil , event . ReasonPoolClosed , ErrPoolDisconnected } p . Lock ( ) p . opened [ c . poolID ] = c p . Unlock ( ) return c , " " , nil }
requires that p be locked
requires that p be locked
// The pool is disconnected or disconnecting, ignore the error from closing the connection.