Skip to content

Commit a34ec48

Browse files
authored
Fix - Don't error when using infinte connect timeout and Entra auth (#2651)
1 parent bad621f commit a34ec48

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ public override async Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthenti
120120
using CancellationTokenSource cts = new();
121121

122122
// Use Connection timeout value to cancel token acquire request after certain period of time.
123-
cts.CancelAfter(parameters.ConnectionTimeout * 1000); // Convert to milliseconds
123+
int timeout = parameters.ConnectionTimeout * 1000; // Convert to milliseconds
124+
if (timeout > 0) // if ConnectionTimeout is 0 or the millis overflows an int, no need to set CancelAfter
125+
{
126+
cts.CancelAfter(timeout);
127+
}
124128

125129
string scope = parameters.Resource.EndsWith(s_defaultScopeSuffix, StringComparison.Ordinal) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix;
126130
string[] scopes = new string[] { scope };

0 commit comments

Comments
 (0)