Skip to content

[Bug] DurationTotalInMs in AuthenticationResultMetadata seems to differ from a Stopwatch measured call #4895

@zachcwillson

Description

@zachcwillson

Library version used

4.63.0

.NET version

net8.0-windows10.0.22621.0, latest patch

Scenario

PublicClient - desktop app

Is this a new or an existing app?

The app is in production, I haven't upgraded MSAL, but started seeing this issue

Issue description and reproduction steps

We observe that the time measurement reported from AuthenticationResultMetadata is not accurate.
image

Relevant code snippets

private static readonly BrokerOptions WamBrokerOptions = new(BrokerOptions.OperatingSystems.Windows);
var publicClient = PublicClientApplicationBuilder
    .Create("{{clientId}}")
    .WithBroker(WamBrokerOptions)
    .WithAuthority(AzureCloudInstance.AzurePublic, AadAuthorityAudience.AzureAdMultipleOrgs)
    .WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
    .Build();

var start = Stopwatch.GetTimestamp();
var authenticationResult = await publicClient
    .AcquireTokenSilent(scopes, PublicClientApplication.OperatingSystemAccount)
    .ExecuteAsync();
var duration = Stopwatch.GetElapsedTime(start);

Console.WriteLine($"DurationTotalInMs: {authenticationResultMetadata.DurationTotalInMs}");
Console.WriteLine($"Stopwatch Measured in ms: {duration.TotalMilliseconds}");

Expected behavior

We expect the Stopwatch measured duration and the DurationTotalInMs to be closer to actual.

Identity provider

Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)

Regression

No response

Solution and workarounds

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions