diff options
Diffstat (limited to 'control/controlhttp')
| -rw-r--r-- | control/controlhttp/client.go | 6 | ||||
| -rw-r--r-- | control/controlhttp/constants.go | 3 | ||||
| -rw-r--r-- | control/controlhttp/http_test.go | 3 |
3 files changed, 9 insertions, 3 deletions
diff --git a/control/controlhttp/client.go b/control/controlhttp/client.go index b0d91bada..facd0f1b1 100644 --- a/control/controlhttp/client.go +++ b/control/controlhttp/client.go @@ -147,13 +147,13 @@ func (a *Dialer) dial(ctx context.Context) (*ClientConn, error) { // before we do anything. if c.DialStartDelaySec > 0 { a.logf("[v2] controlhttp: waiting %.2f seconds before dialing %q @ %v", c.DialStartDelaySec, a.Hostname, c.IP) - tmr := time.NewTimer(time.Duration(c.DialStartDelaySec * float64(time.Second))) + tmr, tmrChannel := a.Clock.NewTimer(time.Duration(c.DialStartDelaySec * float64(time.Second))) defer tmr.Stop() select { case <-ctx.Done(): err = ctx.Err() return - case <-tmr.C: + case <-tmrChannel: } } @@ -319,7 +319,7 @@ func (a *Dialer) dialHost(ctx context.Context, addr netip.Addr) (*ClientConn, er // In case outbound port 80 blocked or MITM'ed poorly, start a backup timer // to dial port 443 if port 80 doesn't either succeed or fail quickly. - try443Timer := time.AfterFunc(a.httpsFallbackDelay(), func() { try(u443) }) + try443Timer := a.Clock.AfterFunc(a.httpsFallbackDelay(), func() { try(u443) }) defer try443Timer.Stop() var err80, err443 error diff --git a/control/controlhttp/constants.go b/control/controlhttp/constants.go index b838f84c4..76c76699f 100644 --- a/control/controlhttp/constants.go +++ b/control/controlhttp/constants.go @@ -11,6 +11,7 @@ import ( "tailscale.com/net/dnscache" "tailscale.com/net/netmon" "tailscale.com/tailcfg" + "tailscale.com/tstime" "tailscale.com/types/key" "tailscale.com/types/logger" ) @@ -89,6 +90,8 @@ type Dialer struct { drainFinished chan struct{} omitCertErrorLogging bool testFallbackDelay time.Duration + + Clock tstime.Clock } func strDef(v1, v2 string) string { diff --git a/control/controlhttp/http_test.go b/control/controlhttp/http_test.go index 3cf790d8c..c5fcdf5c3 100644 --- a/control/controlhttp/http_test.go +++ b/control/controlhttp/http_test.go @@ -25,6 +25,7 @@ import ( "tailscale.com/net/socks5" "tailscale.com/net/tsdial" "tailscale.com/tailcfg" + "tailscale.com/tstest" "tailscale.com/types/key" "tailscale.com/types/logger" ) @@ -204,6 +205,7 @@ func testControlHTTP(t *testing.T, param httpTestParam) { Logf: t.Logf, omitCertErrorLogging: true, testFallbackDelay: 50 * time.Millisecond, + Clock: &tstest.Clock{}, } if proxy != nil { @@ -660,6 +662,7 @@ func TestDialPlan(t *testing.T) { drainFinished: drained, omitCertErrorLogging: true, testFallbackDelay: 50 * time.Millisecond, + Clock: &tstest.Clock{}, } conn, err := a.dial(ctx) |
