Skip to content

Commit 05725c6

Browse files
committed
* Fixed dial timeout processing
1 parent e14f1bd commit 05725c6

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Fixed default grpc dial options
1111
* Replaced single connection for discovery repeater into connection which creates each time for discovery request
1212
* Fixed retry of cluster discovery on initialization
13+
* Fixed dial timeout processing
1314

1415
## v3.42.5
1516
* Fixed closing of `database/sql` connection (aka `YDB` session)

connection.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,6 @@ func connect(ctx context.Context, c *connection) error {
456456
))
457457
}
458458

459-
if t := c.config.DialTimeout(); t > 0 {
460-
var cancel context.CancelFunc
461-
ctx, cancel = context.WithTimeout(ctx, t)
462-
defer cancel()
463-
}
464-
465459
c.balancer, err = balancer.New(ctx,
466460
c.config, c.pool,
467461
append(

internal/balancer/balancer.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@ func (b *Balancer) clusterDiscoveryAttempt(ctx context.Context) (err error) {
9090
)
9191
}()
9292

93-
childCtx, cancel := context.WithTimeout(ctx, b.driverConfig.DialTimeout())
93+
var (
94+
childCtx context.Context
95+
cancel context.CancelFunc
96+
)
97+
if dialTimeout := b.driverConfig.DialTimeout(); dialTimeout > 0 {
98+
childCtx, cancel = context.WithTimeout(ctx, dialTimeout)
99+
} else {
100+
childCtx, cancel = context.WithCancel(ctx)
101+
}
94102
defer cancel()
95103

96104
client, err := b.discoveryClient(childCtx)
@@ -163,12 +171,6 @@ func New(
163171
pool *conn.Pool,
164172
opts ...discoveryConfig.Option,
165173
) (b *Balancer, err error) {
166-
if t := driverConfig.DialTimeout(); t > 0 {
167-
var cancel context.CancelFunc
168-
ctx, cancel = context.WithTimeout(ctx, t)
169-
defer cancel()
170-
}
171-
172174
var (
173175
onDone = trace.DriverOnBalancerInit(
174176
driverConfig.Trace(),

0 commit comments

Comments
 (0)