From a34ec48fb8b4cabbe349ef8019a0a885d3aefab1 Mon Sep 17 00:00:00 2001 From: David Engel Date: Mon, 8 Jul 2024 12:44:40 -0700 Subject: [PATCH] Fix - Don't error when using infinte connect timeout and Entra auth (#2651) --- .../Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs index acf224204a..726410f741 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs @@ -120,7 +120,11 @@ public override async Task AcquireTokenAsync(SqlAuthenti using CancellationTokenSource cts = new(); // Use Connection timeout value to cancel token acquire request after certain period of time. - cts.CancelAfter(parameters.ConnectionTimeout * 1000); // Convert to milliseconds + int timeout = parameters.ConnectionTimeout * 1000; // Convert to milliseconds + if (timeout > 0) // if ConnectionTimeout is 0 or the millis overflows an int, no need to set CancelAfter + { + cts.CancelAfter(timeout); + } string scope = parameters.Resource.EndsWith(s_defaultScopeSuffix, StringComparison.Ordinal) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix; string[] scopes = new string[] { scope };