summaryrefslogtreecommitdiffhomepage
path: root/control/controlhttp
diff options
context:
space:
mode:
Diffstat (limited to 'control/controlhttp')
-rw-r--r--control/controlhttp/client.go11
-rw-r--r--control/controlhttp/constants.go6
2 files changed, 17 insertions, 0 deletions
diff --git a/control/controlhttp/client.go b/control/controlhttp/client.go
index fb220fd0b..b7675f254 100644
--- a/control/controlhttp/client.go
+++ b/control/controlhttp/client.go
@@ -95,6 +95,17 @@ func (a *Dialer) httpsFallbackDelay() time.Duration {
var _ = envknob.RegisterBool("TS_USE_CONTROL_DIAL_PLAN") // to record at init time whether it's in use
func (a *Dialer) dial(ctx context.Context) (*ClientConn, error) {
+ // If we have a last used address, try that first, but time out fairly
+ // aggressively in case it's actually down.
+ if a.LastServerAddr.IsValid() {
+ lastDialCtx, lastDialCancel := context.WithTimeout(ctx, 5*time.Second)
+ defer lastDialCancel()
+ conn, err := a.dialHost(lastDialCtx, a.LastServerAddr)
+ if err == nil {
+ return conn, nil
+ }
+ }
+
// If we don't have a dial plan, just fall back to dialing the single
// host we know about.
useDialPlan := envknob.BoolDefaultTrue("TS_USE_CONTROL_DIAL_PLAN")
diff --git a/control/controlhttp/constants.go b/control/controlhttp/constants.go
index 72161336e..130ad6be2 100644
--- a/control/controlhttp/constants.go
+++ b/control/controlhttp/constants.go
@@ -5,6 +5,7 @@ package controlhttp
import (
"net/http"
+ "net/netip"
"net/url"
"time"
@@ -84,6 +85,11 @@ type Dialer struct {
// plan before falling back to DNS.
DialPlan *tailcfg.ControlDialPlan
+ // LastServerAddr, if valid, is the address that was last used to
+ // (successfully) connect to the control server. It will be prioritized
+ // when making a connection to the server.
+ LastServerAddr netip.Addr
+
proxyFunc func(*http.Request) (*url.URL, error) // or nil
// For tests only