Skip to content

Resilience improvements for instance discovery#5811

Open
bgavrilMS wants to merge 11 commits intomainfrom
bogavril/5809
Open

Resilience improvements for instance discovery#5811
bgavrilMS wants to merge 11 commits intomainfrom
bogavril/5809

Conversation

@bgavrilMS
Copy link
Copy Markdown
Member

@bgavrilMS bgavrilMS commented Mar 5, 2026

Fixes #5804 #5805

If instance discovery fails due to 404 or 502, it should not be attempted again
Instance discovery should have a reasonble timeout

@bgavrilMS bgavrilMS requested a review from a team as a code owner March 5, 2026 14:46
Copilot AI review requested due to automatic review settings March 6, 2026 12:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves AAD instance discovery resilience and performance by avoiding repeated network instance discovery attempts when the endpoint is failing/unreachable, and by bounding discovery latency with a dedicated timeout.

Changes:

  • Cache a fallback instance discovery entry when network instance discovery fails (non-invalid_instance) to avoid retrying discovery on subsequent token requests.
  • Add a per-instance-discovery timeout (default 10s) by linking a timeout CancellationToken into the discovery request flow.
  • Add unit tests covering caching-on-failure and timeout fallback behavior; add a rules doc for cross-SDK reference.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/Microsoft.Identity.Test.Unit/PublicApiTests/InstanceDiscoveryTests.cs Adds tests ensuring instance discovery failures/timeouts are cached and not retried.
src/client/Microsoft.Identity.Client/Internal/RequestContext.cs Makes UserCancellationToken settable to support temporary override during instance discovery.
src/client/Microsoft.Identity.Client/Instance/Discovery/NetworkMetadataProvider.cs Adds instance discovery timeout and links it into the outgoing request.
src/client/Microsoft.Identity.Client/Instance/Discovery/InstanceDiscoveryManager.cs Caches fallback metadata on discovery failure; updates warning text.
docs/instance-discovery-rules.md Adds a detailed description of instance discovery behavior and error-handling rules.

You can also share your feedback on Copilot code review. Take the survey.

Copilot AI review requested due to automatic review settings March 24, 2026 12:12
@bgavrilMS bgavrilMS linked an issue Mar 24, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings March 25, 2026 13:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings March 31, 2026 16:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

@bgavrilMS bgavrilMS changed the title Bogavril/5809 Resilience improvements for instance discovery Mar 31, 2026
Copilot AI review requested due to automatic review settings April 1, 2026 17:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

}
}

[TestMethod]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add one regression test for caller-driven cancellation here? The new timeout path temporarily swaps RequestContext.UserCancellationToken to a linked CTS and relies on the outer catch filter to distinguish timeout from user cancellation. The current timeout test throws TaskCanceledException directly from the mock handler, so it doesn’t exercise the linked-token path or verify that a caller cancellation still bubbles instead of falling back.

@gladjohn
Copy link
Copy Markdown
Contributor

gladjohn commented Apr 1, 2026

looks good, one follow-up test needed.

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.

[Feature Request] Instance discovery should timeout [Bug] If instance discovery fails due to 404 or 502, it should not be attempted again

5 participants