Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion client/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log/slog"
"math"
"math/rand"
"net"
"sync"
"time"

Expand Down Expand Up @@ -118,7 +119,7 @@ func NewPoolWithOptions(
idlePingTimeout: Timestamp(math.Ceil(MaxIdleTimeoutWithoutPing.Seconds())),

connect: func() (*Conn, error) {
return Connect(addr, user, password, dbName, po.connOptions...)
return ConnectWithDialer(context.Background(), "", addr, user, password, dbName, po.dialer, po.connOptions...)
},

readyConnection: make(chan Connection),
Expand Down Expand Up @@ -606,10 +607,12 @@ func (pool *Pool) checkConnection(ctx context.Context) error {

// getDefaultPoolOptions returns pool config for low load services
func getDefaultPoolOptions() poolOptions {
dialer := &net.Dialer{Timeout: 10 * time.Second}
return poolOptions{
logger: slog.Default(),
minAlive: 1,
maxAlive: 10,
maxIdle: 2,
dialer: dialer.DialContext,
}
}
8 changes: 8 additions & 0 deletions client/pool_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type (
password string
dbName string

dialer Dialer

connOptions []Option

newPoolPingTimeout time.Duration
Expand Down Expand Up @@ -59,3 +61,9 @@ func WithNewPoolPingTimeout(timeout time.Duration) PoolOption {
o.newPoolPingTimeout = timeout
}
}

func WithDialer(dialer Dialer) PoolOption {
return func(o *poolOptions) {
o.dialer = dialer
}
}
Loading