@@ -25,6 +25,29 @@ import (
25
25
"time"
26
26
)
27
27
28
+ // TransportPool is a progressive and non-blocking pool
29
+ // for http.Transport objects, optimised for Gargabe Collection
30
+ // and without a hard limit on number of objects created.
31
+ //
32
+ // Its main purpose is to enable for transport objects to be
33
+ // used across helm chart download requests and helm/pkg/getter
34
+ // instances by leveraging the getter.WithTransport(t) construct.
35
+ //
36
+ // The use of this pool improves the default behaviour of helm getter
37
+ // which creates a new connection per request, or per getter instance,
38
+ // resulting on unnecessary TCP connections with the target.
39
+ //
40
+ // http.Transport objects may contain sensitive material and also have
41
+ // settings that may impact the security of HTTP operations using
42
+ // them (i.e. InsecureSkipVerify). Therefore, ensure that they are
43
+ // used in a thread-safe way, and also by reseting TLS specific state
44
+ // after each use.
45
+ //
46
+ // Calling the Release(t) function will reset TLS specific state whilst
47
+ // also releasing the transport back to the pool to be reused.
48
+ //
49
+ // xref: https://github.com/helm/helm/pull/10568
50
+ // xref2: https://github.com/fluxcd/source-controller/issues/578
28
51
type TransportPool struct {
29
52
}
30
53
@@ -34,6 +57,14 @@ var pool = &sync.Pool{
34
57
DisableCompression : true ,
35
58
Proxy : http .ProxyFromEnvironment ,
36
59
60
+ // Due to the non blocking nature of this approach,
61
+ // at peak usage a higher number of transport objects
62
+ // may be created. sync.Pool will ensure they are
63
+ // gargage collected when/if needed.
64
+ //
65
+ // By setting a low value to IdleConnTimeout the connections
66
+ // will be closed after that period of inactivity, allowing the
67
+ // transport to be garbage collected.
37
68
IdleConnTimeout : 60 * time .Second ,
38
69
39
70
// use safe defaults based off http.DefaultTransport
@@ -50,7 +81,7 @@ var pool = &sync.Pool{
50
81
// NewOrIdle tries to return an existing transport that is not currently being used.
51
82
// If none is found, creates a new Transport instead.
52
83
//
53
- // tlsConfig sets the TLSClientConfig for the transport and can be nil .
84
+ // tlsConfig can optionally set the TLSClientConfig for the transport.
54
85
func NewOrIdle (tlsConfig * tls.Config ) * http.Transport {
55
86
t := pool .Get ().(* http.Transport )
56
87
t .TLSClientConfig = tlsConfig
0 commit comments