From 1fa9780d3ec6445ecc5cdbfffc79b1883577ea67 Mon Sep 17 00:00:00 2001 From: Olivier Boucher Date: Sat, 20 Dec 2025 09:24:34 -0500 Subject: [PATCH] client/pool: add Option to supply custom Dialer --- client/pool.go | 5 ++++- client/pool_options.go | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/client/pool.go b/client/pool.go index 5cab93a1a..48ce2ce69 100644 --- a/client/pool.go +++ b/client/pool.go @@ -5,6 +5,7 @@ import ( "log/slog" "math" "math/rand" + "net" "sync" "time" @@ -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), @@ -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, } } diff --git a/client/pool_options.go b/client/pool_options.go index 1dec5ed00..428ed8c54 100644 --- a/client/pool_options.go +++ b/client/pool_options.go @@ -18,6 +18,8 @@ type ( password string dbName string + dialer Dialer + connOptions []Option newPoolPingTimeout time.Duration @@ -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 + } +}