Skip to content

Commit 9324ab2

Browse files
Apply Timeout to HttpClient instances created with authentication (#1277)
When AddAuthentication() is called, GxHttpClient passes a non-empty authCollection to GetHttpClientInstance, so CacheableInstance returns false and the non-cached branch builds a fresh HttpClient. That branch never set client.Timeout, leaving the default 100s and silently ignoring the user-configured Timeout property. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> (cherry picked from commit bb1a5c6) # Conflicts: # dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs
1 parent b3f4348 commit 9324ab2

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ private async Task<byte[]> ReceiveDataAsync()
160160
internal static ConcurrentDictionary<string, HttpClient> _httpClientInstances = new ConcurrentDictionary<string, HttpClient>();
161161
private static HttpClient GetHttpClientInstance(Uri URI, int timeout, ArrayList authCollection, ArrayList authProxyCollection, X509Certificate2Collection certificateCollection, List<string> fileCertificateCollection, string proxyHost, int proxyPort, out bool disposableInstance)
162162
{
163+
HttpClient value;
163164
if (CacheableInstance(authCollection, authProxyCollection))
164165
{
165-
HttpClient value;
166166
disposableInstance = false;
167167
string key = HttpClientInstanceIdentifier(proxyHost, proxyPort, fileCertificateCollection, timeout);
168168
if (_httpClientInstances.TryGetValue(key, out value))
@@ -189,7 +189,9 @@ private static HttpClient GetHttpClientInstance(Uri URI, int timeout, ArrayList
189189
else
190190
{
191191
disposableInstance = true;
192-
return new HttpClient(GetHandler(URI, authCollection, authProxyCollection, certificateCollection, proxyHost, proxyPort));
192+
value = new HttpClient(GetHandler(URI, authCollection, authProxyCollection, certificateCollection, proxyHost, proxyPort));
193+
value.Timeout = TimeSpan.FromMilliseconds(timeout);
194+
return value;
193195
}
194196
}
195197

@@ -1024,7 +1026,7 @@ async Task ReadResponseDataAsync()
10241026
}
10251027
}
10261028
}
1027-
#endif
1029+
#endif
10281030
bool UseOldHttpClient(string name)
10291031
{
10301032
if (Config.GetValueOf("useoldhttpclient", out string useOld) && useOld.StartsWith("y", StringComparison.OrdinalIgnoreCase))

0 commit comments

Comments
 (0)