mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 11:05:45 +00:00
{control,net}: close idle connections of custom transports
I noticed a few places with custom http.Transport where we are not closing idle connections when transport is no longer used. Updates tailscale/corp#21609 Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
parent
e3f047618b
commit
227509547f
@ -333,6 +333,9 @@ func (c *Direct) Close() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.noiseClient = nil
|
c.noiseClient = nil
|
||||||
|
if tr, ok := c.httpc.Transport.(*http.Transport); ok {
|
||||||
|
tr.CloseIdleConnections()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,6 +281,7 @@ type nameIP struct {
|
|||||||
func bootstrapDNSMap(ctx context.Context, serverName string, serverIP netip.Addr, queryName string, logf logger.Logf, ht *health.Tracker, netMon *netmon.Monitor) (dnsMap, error) {
|
func bootstrapDNSMap(ctx context.Context, serverName string, serverIP netip.Addr, queryName string, logf logger.Logf, ht *health.Tracker, netMon *netmon.Monitor) (dnsMap, error) {
|
||||||
dialer := netns.NewDialer(logf, netMon)
|
dialer := netns.NewDialer(logf, netMon)
|
||||||
tr := http.DefaultTransport.(*http.Transport).Clone()
|
tr := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
|
tr.DisableKeepAlives = true // This transport is meant to be used once.
|
||||||
tr.Proxy = tshttpproxy.ProxyFromEnvironment
|
tr.Proxy = tshttpproxy.ProxyFromEnvironment
|
||||||
tr.DialContext = func(ctx context.Context, netw, addr string) (net.Conn, error) {
|
tr.DialContext = func(ctx context.Context, netw, addr string) (net.Conn, error) {
|
||||||
return dialer.DialContext(ctx, "tcp", net.JoinHostPort(serverIP.String(), "443"))
|
return dialer.DialContext(ctx, "tcp", net.JoinHostPort(serverIP.String(), "443"))
|
||||||
|
@ -166,6 +166,7 @@ func (d *Dialer) Close() error {
|
|||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
d.activeSysConns = nil
|
d.activeSysConns = nil
|
||||||
|
d.PeerAPITransport().CloseIdleConnections()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user