@@ -21,7 +21,7 @@ public record struct Registry(Uri BaseUri)
21
21
22
22
public async Task < Image > GetImageManifest ( string name , string reference )
23
23
{
24
- using HttpClient client = GetClient ( ) ;
24
+ HttpClient client = GetClient ( ) ;
25
25
26
26
var response = await client . GetAsync ( new Uri ( BaseUri , $ "/v2/{ name } /manifests/{ reference } ") ) ;
27
27
@@ -72,7 +72,7 @@ public async Task<string> DownloadBlob(string name, Descriptor descriptor)
72
72
73
73
// No local copy, so download one
74
74
75
- using HttpClient client = GetClient ( ) ;
75
+ HttpClient client = GetClient ( ) ;
76
76
77
77
var response = await client . GetAsync ( new Uri ( BaseUri , $ "/v2/{ name } /blobs/{ descriptor . Digest } ") , HttpCompletionOption . ResponseHeadersRead ) ;
78
78
@@ -103,7 +103,7 @@ public async Task Push(Layer layer, string name, Action<string> logProgressMessa
103
103
104
104
private readonly async Task UploadBlob ( string name , string digest , Stream contents )
105
105
{
106
- using HttpClient client = GetClient ( ) ;
106
+ HttpClient client = GetClient ( ) ;
107
107
108
108
if ( await BlobAlreadyUploaded ( name , digest , client ) )
109
109
{
@@ -157,9 +157,16 @@ private readonly async Task<bool> BlobAlreadyUploaded(string name, string digest
157
157
return false ;
158
158
}
159
159
160
+ private static HttpClient _client = CreateClient ( ) ;
161
+
160
162
private static HttpClient GetClient ( )
161
163
{
162
- var clientHandler = new AuthHandshakeMessageHandler ( new HttpClientHandler ( ) { UseDefaultCredentials = true } ) ;
164
+ return _client ;
165
+ }
166
+
167
+ private static HttpClient CreateClient ( )
168
+ {
169
+ var clientHandler = new AuthHandshakeMessageHandler ( new SocketsHttpHandler ( ) { PooledConnectionLifetime = TimeSpan . FromMilliseconds ( 10 /* total guess */ ) } ) ;
163
170
HttpClient client = new ( clientHandler ) ;
164
171
165
172
client . DefaultRequestHeaders . Accept . Clear ( ) ;
@@ -179,7 +186,7 @@ public async Task Push(Image x, string name, string? tag, string baseName, Actio
179
186
{
180
187
tag ??= "latest" ;
181
188
182
- using HttpClient client = GetClient ( ) ;
189
+ HttpClient client = GetClient ( ) ;
183
190
var reg = this ;
184
191
await Task . WhenAll ( x . LayerDescriptors . Select ( async descriptor => {
185
192
string digest = descriptor . Digest ;
0 commit comments