Skip to content

[V3] Add the ConnectTimeout property on the service client config for the … #3820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"core": {
"updateMinimum": true,
"type": "Patch",
"changeLogMessages": [
"Add the ConnectTimeout property on the service client config for the .NET 8 target of the SDK."
]
}
}
25 changes: 25 additions & 0 deletions sdk/src/Core/Amazon.Runtime/ClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,31 @@ public TimeSpan? Timeout
}
}

#if NET8_0_OR_GREATER
TimeSpan? _connectTimeout;

/// <summary>
/// Gets and sets the connection timeout that will be set on the HttpClient used by the service client to make requests.
/// The connection timeout is used control the wait time for the connection to be established to the service. The default
/// connection timeout for the HttpClient is infinite waiting period.
/// </summary>
public TimeSpan? ConnectTimeout
{
get
{
if (!this._connectTimeout.HasValue)
return null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I would like to default this to DefaultConfiguration.ConnectTimeout instead of null but changing the default timeout would be a breaking change. Maybe when we do a 4.1 we can reconsider the default.


return this._connectTimeout.Value;
}
set
{
ValidateTimeout(value);
this._connectTimeout = value;
}
}
#endif

#if AWS_ASYNC_API
/// <summary>
/// Generates a <see cref="CancellationToken"/> based on the value
Expand Down
8 changes: 8 additions & 0 deletions sdk/src/Core/Amazon.Runtime/IClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ public partial interface IClientConfig
/// </remarks>
TimeSpan? Timeout { get; }

#if NET8_0_OR_GREATER
/// <summary>
/// Gets the connection timeout that will be set on the HttpClient used by the service client to make requests.
/// The connection timeout is used control the wait time for the connection to be established to the service.
/// </summary>
TimeSpan? ConnectTimeout { get; }
#endif

/// <summary>
/// Configures the endpoint calculation for a service to go to a dual stack (ipv6 enabled) endpoint
/// for the configured region.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,16 @@ private static HttpClient CreateHttpClient(IClientConfig clientConfig)
/// <returns></returns>
private static HttpClient CreateManagedHttpClient(IClientConfig clientConfig)
{
#if NET8_0_OR_GREATER
var httpMessageHandler = new SocketsHttpHandler();

if (clientConfig.ConnectTimeout.HasValue)
{
httpMessageHandler.ConnectTimeout = clientConfig.ConnectTimeout.Value;
}
#else
var httpMessageHandler = new HttpClientHandler();
#endif

if (clientConfig.MaxConnectionsPerServer.HasValue)
httpMessageHandler.MaxConnectionsPerServer = clientConfig.MaxConnectionsPerServer.Value;
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/Core/Amazon.Runtime/_netstandard/ClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ internal static string CreateConfigUniqueString(IClientConfig clientConfig)
if (clientConfig.MaxConnectionsPerServer.HasValue)
uniqueString = string.Concat(uniqueString, "MaxConnectionsPerServer:", clientConfig.MaxConnectionsPerServer.Value.ToString());

#if NET8_0_OR_GREATER
if (clientConfig.ConnectTimeout.HasValue)
uniqueString = string.Concat(uniqueString, "ConnectTimeout:", clientConfig.ConnectTimeout.Value.ToString());
#endif

return uniqueString;
}

Expand Down
3 changes: 3 additions & 0 deletions sdk/test/NetStandard/UnitTests/ClientConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class ClientConfigTests
"DisableLogging",
"ProxyCredentials",
"Timeout",
#if NET8_0_OR_GREATER
"ConnectTimeout",
#endif
"UseDualstackEndpoint",
"UseFIPSEndpoint",
"ProxyHost",
Expand Down