From ea085663ea75ee2c84364244da6b0d195d0b76e0 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Mon, 21 Oct 2019 20:52:16 -0500 Subject: [PATCH] slight cleanup of dial's timeout --- src/yggdrasil/dialer.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/yggdrasil/dialer.go b/src/yggdrasil/dialer.go index 8ef0582f..47a68813 100644 --- a/src/yggdrasil/dialer.go +++ b/src/yggdrasil/dialer.go @@ -72,19 +72,16 @@ func (d *Dialer) DialByNodeIDandMask(ctx context.Context, nodeID, nodeMask *cryp return nil, err } conn.session.setConn(nil, conn) - var c context.Context var cancel context.CancelFunc - const timeout = 6 * time.Second - if ctx != nil { - c, cancel = context.WithTimeout(ctx, timeout) - } else { - c, cancel = context.WithTimeout(context.Background(), timeout) + if ctx == nil { + ctx = context.Background() } + ctx, cancel = context.WithTimeout(ctx, 6*time.Second) defer cancel() select { case <-conn.session.init: return conn, nil - case <-c.Done(): + case <-ctx.Done(): conn.Close() return nil, errors.New("session handshake timeout") }