Skip to content

ActiveDirectoryAuthenticationProvider.AcquireTokenAsync method fails when ConnectTimeout set to 0 or >= int.MaxValue/1000 #2563

Closed

Description

@chris5287

Well that was fun to debug!

cts.CancelAfter(parameters.ConnectionTimeout * 1000); // Convert to milliseconds

As the ConnectionTimeout is used to set the cancellation token's CancelAfter * 1000...

  • If ConnectionTimeout = 0 then 0 * 1000 = 0 - this causes the cancellation token to immediately expire, so all operations such as gather the tenant metadata fail with A task was canceled exception message (which is what led me down this rabbit hole).
  • If ConnectionTimeout = int.MaxValue (or any value greater than int.MaxValue / 1000) then int.MaxValue * 1000 throws as the result is larger than int.

Ideally this needs more defensive coding, eg:

  • When ConnectionTimeout == 0 we do not require a CancelAfter?
  • When ConnectionTimeout >= int.MaxValue / 1000 set the CancelAfter to int.MaxValue?

Activity

  1. dauinsight commented on Jun 12, 2024

    @dauinsight
    Contributor

    Thanks for pointing this out. We'll likely add this to our backlog

  2. added 2 commits that reference this issue on Jul 5, 2024
    3f610ad
    939bcc4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions