Open bruno-brant opened 1 month ago
FYI @brentschmaltz
I like the idea to use Epoch time as a long.
I like the idea to use Epoch time as a long.
Longs can still cause an issue in 32-bit architectures unless we use Interlocked or any other synchronization strategy. A int32 is always atomic.
Given the use case, maybe an int32 would suffice? I know the max time shouldn't larger than an int.MaxValue, not sure if the subtraction is cheaper than an interlocked though.
@brentschmaltz We don't need to store the epoch time, just the offset, which should always be capturable in an int. I think this is the point @bruno-brant is trying to make.
@keegan-caruso that makes sense also, hadn't thought about 32bit architectures, that is a good point and should be considered.
Which version of Microsoft.IdentityModel are you using? Microsoft.IdentityModel 8.1.2
Where is the issue?
Description
Every calling thread to
ConfigurationManager.GetConfigurationAsync
will result in a read to_syncAfter
to check if a sync should be started; later, a background thread will update_syncAfter
with the new sync time.syncAfter
is a DateTimeOffset, a struct, so writes to it aren't atomic, so there's a possibility that the calling thread will read corrupt data.Possible solution
_syncAfter
so that it can be atomically read/written - we could refactor it to be total seconds (int32
) or any other type that is atomic.Additional context / logs / screenshots / links to code