From fbbc3c9e3017064bc003a36079bd1470c7f18a09 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 14 Jan 2025 00:01:57 -0800 Subject: [PATCH] wait for connection to shut down when the Dial context is cancelled (#4872) --- client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client.go b/client.go index 1782cde81..7a99a0f27 100644 --- a/client.go +++ b/client.go @@ -245,6 +245,11 @@ func (c *client) dial(ctx context.Context) error { select { case <-ctx.Done(): c.conn.destroy(nil) + // wait until the Go routine that called Connection.run() returns + select { + case <-errorChan: + case <-recreateChan: + } return context.Cause(ctx) case err := <-errorChan: return err