From b0b1cdc71d4ec48aa1f78866d03bd9c92e0fd3f9 Mon Sep 17 00:00:00 2001 From: Achille Date: Fri, 12 Jun 2020 23:07:22 -0700 Subject: [PATCH] propagate the caller's context to the dial function (#460) --- transport.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/transport.go b/transport.go index a163e0b31..50f7c0ccf 100644 --- a/transport.go +++ b/transport.go @@ -897,7 +897,7 @@ func (g *connGroup) grabConnOrConnect(ctx context.Context) (*conn, error) { errChan := make(chan error) go func() { - c, err := g.connect() + c, err := g.connect(ctx) if err != nil { select { case errChan <- err: @@ -991,10 +991,10 @@ func (g *connGroup) releaseConn(c *conn) bool { return true } -func (g *connGroup) connect() (*conn, error) { +func (g *connGroup) connect(ctx context.Context) (*conn, error) { deadline := time.Now().Add(g.pool.dialTimeout) - ctx, cancel := context.WithDeadline(context.Background(), deadline) + ctx, cancel := context.WithDeadline(ctx, deadline) defer cancel() netConn, err := g.pool.dial(ctx, g.network, g.address)