Skip to content

Fix race condition in ConfigurationManager refresh state (#3142)#3516

Open
dipeshchaudhari3255 wants to merge 1 commit into
AzureAD:devfrom
dipeshchaudhari3255:fix/configurationmanager-thread-safety-3142-final
Open

Fix race condition in ConfigurationManager refresh state (#3142)#3516
dipeshchaudhari3255 wants to merge 1 commit into
AzureAD:devfrom
dipeshchaudhari3255:fix/configurationmanager-thread-safety-3142-final

Conversation

@dipeshchaudhari3255
Copy link
Copy Markdown

Fix race condition in ConfigurationManager refresh state (#3142)

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • If any gains or losses in performance are possible, you've included benchmarks for your changes.
  • There's an open issue for the PR that you are making.

Summary of the changes

Fix race condition caused by non-atomic refresh timestamp access.

Description

Issue #3142 reports a thread-safety concern around concurrent access to refresh timing state in ConfigurationManager.

The fields _syncAfter and _lastRequestRefresh were used by multiple threads to determine whether a configuration refresh was required. These values were accessed concurrently without atomic read/write operations, which could result in inconsistent observations under heavy concurrency and lead to duplicate metadata retrievals.

Changes

Validation

The issue was reproduced using a test application that generated 50 concurrent refresh requests.

Before the fix:

  • Request count: 50
  • Actual metadata HTTP calls: 2

After the fix:

  • Request count: 50
  • Actual metadata HTTP calls: 1

This confirms that concurrent refresh requests no longer trigger multiple simultaneous metadata retrievals.

Fixes #3142

Store _syncAfter and _lastRequestRefresh as tick values and use
Interlocked.Read/Interlocked.Exchange to ensure atomic access.

This prevents concurrent callers from observing torn timestamp
state and reduces duplicate metadata retrievals under load.
@dipeshchaudhari3255 dipeshchaudhari3255 requested a review from a team as a code owner June 2, 2026 09:00
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] Ensure updates to state are done atomically in ConfigurationManager

2 participants