Skip to content

Commit 87be738

Browse files
committed
- Fixed timestamp truncation from long to uint causing cached tokens to be erroneously expired.
1 parent ffab846 commit 87be738

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlAuthenticationProviderException.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,11 @@
6767
ShouldRetry is false.
6868
</summary>
6969
</RetryPeriod>
70+
<ToString>
71+
<returns>
72+
A string that includes the base exception information along with all
73+
property values.
74+
</returns>
75+
</ToString>
7076
</members>
7177
</docs>

src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationProviderException.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,13 @@ protected SqlAuthenticationProviderException(
4747
/// <include file='../doc/SqlAuthenticationProviderException.xml' path='docs/members[@name="SqlAuthenticationProviderException"]/RetryPeriod/*'/>
4848
public int RetryPeriod { get; }
4949

50+
/// <include file='../doc/SqlAuthenticationProviderException.xml' path='docs/members[@name="SqlAuthenticationProviderException"]/ToString/*'/>
51+
public override string ToString()
52+
{
53+
return base.ToString() +
54+
$" Method={Method} FailureCode={FailureCode}" +
55+
$" ShouldRetry={ShouldRetry} RetryPeriod={RetryPeriod}";
56+
}
57+
5058
private const string Unknown = "Unknown";
5159
}

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ internal sealed class SqlInternalConnectionTds : SqlInternalConnection, IDisposa
131131
internal bool _federatedAuthenticationInfoReceived;
132132

133133
// The Federated Authentication returned by TryGetFedAuthTokenLocked or GetFedAuthToken.
134-
SqlFedAuthToken _fedAuthToken = null;
134+
private SqlFedAuthToken _fedAuthToken = null;
135+
135136
internal byte[] _accessTokenInBytes;
136137
internal readonly Func<SqlAuthenticationParameters, CancellationToken, Task<SqlAuthenticationToken>> _accessTokenCallback;
137138
internal readonly SspiContextProvider _sspiContextProvider;
@@ -2417,7 +2418,7 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
24172418
// generating a new access token on this thread.
24182419
_fedAuthToken = new(
24192420
dbConnectionPoolAuthenticationContext.AccessToken,
2420-
(uint)dbConnectionPoolAuthenticationContext.ExpirationTime.ToFileTime());
2421+
dbConnectionPoolAuthenticationContext.ExpirationTime.ToFileTime());
24212422
}
24222423

24232424
Debug.Assert(_fedAuthToken != null && _fedAuthToken.AccessToken != null, "_fedAuthToken and _fedAuthToken.AccessToken cannot be null.");

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
24732473
// generating a new access token on this thread.
24742474
_fedAuthToken = new(
24752475
dbConnectionPoolAuthenticationContext.AccessToken,
2476-
(uint)dbConnectionPoolAuthenticationContext.ExpirationTime.ToFileTime());
2476+
dbConnectionPoolAuthenticationContext.ExpirationTime.ToFileTime());
24772477
}
24782478

24792479
Debug.Assert(_fedAuthToken != null && _fedAuthToken.AccessToken != null, "_fedAuthToken and _fedAuthToken.AccessToken cannot be null.");

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlUtil.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,17 +1451,6 @@ internal static Exception UnsupportedFeatureAndToken(SqlInternalConnectionTds in
14511451
return exc;
14521452
}
14531453

1454-
internal static Exception Azure_ManagedIdentityException(string msg)
1455-
{
1456-
SqlErrorCollection errors = new SqlErrorCollection
1457-
{
1458-
new SqlError(0, (byte)0x00, TdsEnums.FATAL_ERROR_CLASS, null, msg, "", 0)
1459-
};
1460-
SqlException exc = SqlException.CreateException(errors, null);
1461-
exc._doNotReconnect = true; // disable open retry logic on this error
1462-
return exc;
1463-
}
1464-
14651454
#region Always Encrypted Errors
14661455

14671456
#region Always Encrypted - Certificate Store Provider Errors

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ internal sealed class SqlFedAuthToken
156156

157157
internal SqlFedAuthToken(
158158
byte[] accessToken,
159-
uint expirationFileTime)
159+
long expirationFileTime)
160160
{
161161
AccessToken = accessToken;
162162
DataLen = (uint)AccessToken.Length;

0 commit comments

Comments
 (0)