0.38.6_agent_hotfix

This commit is contained in:
Mateusz Gruszczyński committed 2026-11-19 08:53:34 +01:00
1 parent 1239ff524d
commit d4a604970e
14 files changed
+478 -162

No files matched your search

+24 -4
View File
@@ -10,23 +10,43 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"
)
type unixRoundTripper struct{ sock string }
func (u unixRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
// Each Docker socket gets one shared transport. Creating one per RoundTrip
// leaks idle connections and their goroutines when keep-alive is enabled.
// The configured socket is stable during the lifetime of the agent.
var unixTransports sync.Map // map[string]*http.Transport
func unixTransport(sock string) *http.Transport {
if existing, ok := unixTransports.Load(sock); ok {
return existing.(*http.Transport)
}
transport := &http.Transport{
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
var d net.Dialer
return d.DialContext(ctx, "unix", u.sock)
return d.DialContext(ctx, "unix", sock)
},
DisableKeepAlives: false,
MaxIdleConns: 16,
MaxIdleConnsPerHost: 16,
MaxConnsPerHost: 32,
IdleConnTimeout: 30 * time.Second,
}
actual, loaded := unixTransports.LoadOrStore(sock, transport)
if loaded {
transport.CloseIdleConnections()
}
return actual.(*http.Transport)
}
func (u unixRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
clone := req.Clone(req.Context())
clone.URL.Scheme = "http"
clone.URL.Host = "docker"
return transport.RoundTrip(clone)
return unixTransport(u.sock).RoundTrip(clone)
}
func dockerContainers(ctx context.Context, sock string) ([]dockerContainer, error) {