Skip to content
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

Make updates to syncAfter and lastRefreshRequest atomic #3090

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

keegan-caruso
Copy link
Contributor

@keegan-caruso keegan-caruso commented Jan 11, 2025

Make updates to syncAfter and lastRefreshRequest atomic

Description

syncAfter can be updated on a background thread,
lastRefreshRequest could be simultaneously updated
by different threads as there is not a lock around
the check and update.

To be able to do an atomic write, DateTimeOffset fields had
to be switched to DateTime fields. DateTime is a struct
with a single ulong field, DateTimeOffset has two fields,
one for the datetime, one for the offset. DateTime can
be treated as a long for this reason (and is in DateTime's ToBinary method).

This also means ConfigurationManager can continue to use DateTime instead of an
int, which is much more ergonomic.

See the [implementation] for when you can't use a long and need to use a ulong: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/DateTime.cs#L1316

Fixes #2900

@keegan-caruso keegan-caruso requested a review from GeoK January 12, 2025 00:39
Copy link

Summary

Summary
Generated on: 1/12/2025 - 12:51:28 AM
Coverage date: 1/12/2025 - 12:42:06 AM - 1/12/2025 - 12:51:02 AM
Parser: MultiReport (60x Cobertura)
Assemblies: 1
Classes: 7
Files: 2
Line coverage: 80.3% (620 of 772)
Covered lines: 620
Uncovered lines: 152
Coverable lines: 772
Total lines: 483
Branch coverage: 67.8% (228 of 336)
Covered branches: 228
Total branches: 336
Method coverage: Feature is only available for sponsors

Coverage

Microsoft.IdentityModel.JsonWebTokens - 80.3%
Name Line Branch
Microsoft.IdentityModel.JsonWebTokens 80.3% 67.8%
Microsoft.IdentityModel.JsonWebTokens.JwtTokenUtilities 100%
System.Text.RegularExpressions.Generated 80.3% 67.8%
System.Text.RegularExpressions.Generated 80.3% 67.8%
System.Text.RegularExpressions.Generated.<RegexGenerator_g>F12A1AEDDDFE32BA
DF4DBFF323AF1BCB48B9F9721B7CD3E05F5E034CF225E3DF8__CreateJweRegex_1
79.2% 68%
System.Text.RegularExpressions.Generated.<RegexGenerator_g>F12A1AEDDDFE32BA
DF4DBFF323AF1BCB48B9F9721B7CD3E05F5E034CF225E3DF8__CreateJwsRegex_0
81.4% 67.6%
System.Text.RegularExpressions.Generated.<RegexGenerator_g>F334844C618E00D3
CEC5D3FE0D00CF0141BBEE98635313BB2CB8D3921464CE05A__CreateJweRegex_1
79.2% 68%
System.Text.RegularExpressions.Generated.<RegexGenerator_g>F334844C618E00D3
CEC5D3FE0D00CF0141BBEE98635313BB2CB8D3921464CE05A__CreateJwsRegex_0
81.4% 67.6%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Race condition on ConfigurationManager._syncAfter
1 participant