@@ -99,14 +99,7 @@ func NewServerTailnet(
99
99
transport : tailnetTransport .Clone (),
100
100
}
101
101
tn .transport .DialContext = tn .dialContext
102
-
103
- // Bugfix: for some reason all calls to tn.dialContext come from
104
- // "localhost", causing connections to be cached and requests to go to the
105
- // wrong workspaces. This disables keepalives for now until the root cause
106
- // can be found.
107
- tn .transport .MaxIdleConnsPerHost = - 1
108
- tn .transport .DisableKeepAlives = true
109
-
102
+ tn .transport .MaxIdleConnsPerHost = 10
110
103
tn .transport .MaxIdleConns = 0
111
104
// We intentionally don't verify the certificate chain here.
112
105
// The connection to the workspace is already established and most
@@ -308,7 +301,15 @@ type ServerTailnet struct {
308
301
}
309
302
310
303
func (s * ServerTailnet ) ReverseProxy (targetURL , dashboardURL * url.URL , agentID uuid.UUID ) * httputil.ReverseProxy {
311
- proxy := httputil .NewSingleHostReverseProxy (targetURL )
304
+ // Rewrite the targetURL's Host to point to the agent's IP. This is
305
+ // necessary because due to TCP connection caching, each agent needs to be
306
+ // addressed invidivually. Otherwise, all connections get dialed as
307
+ // "localhost:port", causing connections to be shared across agents.
308
+ tgt := * targetURL
309
+ _ , port , _ := net .SplitHostPort (tgt .Host )
310
+ tgt .Host = net .JoinHostPort (tailnet .IPFromUUID (agentID ).String (), port )
311
+
312
+ proxy := httputil .NewSingleHostReverseProxy (& tgt )
312
313
proxy .ErrorHandler = func (w http.ResponseWriter , r * http.Request , err error ) {
313
314
site .RenderStaticErrorPage (w , r , site.ErrorPageData {
314
315
Status : http .StatusBadGateway ,
0 commit comments