diff --git a/generator/.DevConfigs/378BAE5D-9864-4E0F-853F-BBA0ACD3F60D.json b/generator/.DevConfigs/378BAE5D-9864-4E0F-853F-BBA0ACD3F60D.json new file mode 100644 index 000000000000..bd448abf1296 --- /dev/null +++ b/generator/.DevConfigs/378BAE5D-9864-4E0F-853F-BBA0ACD3F60D.json @@ -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." + ] + } +} \ No newline at end of file diff --git a/sdk/src/Core/Amazon.Runtime/ClientConfig.cs b/sdk/src/Core/Amazon.Runtime/ClientConfig.cs index 53fec09e9c54..e8ed7b187ff0 100644 --- a/sdk/src/Core/Amazon.Runtime/ClientConfig.cs +++ b/sdk/src/Core/Amazon.Runtime/ClientConfig.cs @@ -832,6 +832,31 @@ public TimeSpan? Timeout } } +#if NET8_0_OR_GREATER + TimeSpan? _connectTimeout; + + /// + /// 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. + /// + public TimeSpan? ConnectTimeout + { + get + { + if (!this._connectTimeout.HasValue) + return null; + + return this._connectTimeout.Value; + } + set + { + ValidateTimeout(value); + this._connectTimeout = value; + } + } +#endif + #if AWS_ASYNC_API /// /// Generates a based on the value diff --git a/sdk/src/Core/Amazon.Runtime/IClientConfig.cs b/sdk/src/Core/Amazon.Runtime/IClientConfig.cs index 9ee2458efd7e..3d16d69aba79 100644 --- a/sdk/src/Core/Amazon.Runtime/IClientConfig.cs +++ b/sdk/src/Core/Amazon.Runtime/IClientConfig.cs @@ -245,6 +245,14 @@ public partial interface IClientConfig /// TimeSpan? Timeout { get; } +#if NET8_0_OR_GREATER + /// + /// 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. + /// + TimeSpan? ConnectTimeout { get; } +#endif + /// /// Configures the endpoint calculation for a service to go to a dual stack (ipv6 enabled) endpoint /// for the configured region. diff --git a/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_netstandard/HttpRequestMessageFactory.cs b/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_netstandard/HttpRequestMessageFactory.cs index f81f17e66ca5..2e242450e2c8 100644 --- a/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_netstandard/HttpRequestMessageFactory.cs +++ b/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_netstandard/HttpRequestMessageFactory.cs @@ -245,7 +245,16 @@ private static HttpClient CreateHttpClient(IClientConfig clientConfig) /// 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; diff --git a/sdk/src/Core/Amazon.Runtime/_netstandard/ClientConfig.cs b/sdk/src/Core/Amazon.Runtime/_netstandard/ClientConfig.cs index 52d1735331d4..28594a4f59f4 100644 --- a/sdk/src/Core/Amazon.Runtime/_netstandard/ClientConfig.cs +++ b/sdk/src/Core/Amazon.Runtime/_netstandard/ClientConfig.cs @@ -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; } diff --git a/sdk/test/NetStandard/UnitTests/ClientConfigTests.cs b/sdk/test/NetStandard/UnitTests/ClientConfigTests.cs index 9c7945266933..25b63d59a4be 100644 --- a/sdk/test/NetStandard/UnitTests/ClientConfigTests.cs +++ b/sdk/test/NetStandard/UnitTests/ClientConfigTests.cs @@ -38,6 +38,9 @@ public class ClientConfigTests "DisableLogging", "ProxyCredentials", "Timeout", +#if NET8_0_OR_GREATER + "ConnectTimeout", +#endif "UseDualstackEndpoint", "UseFIPSEndpoint", "ProxyHost",