Skip to content

Auth concurrency guard's logging is asymmetric (winner logs, waiters don't) #10

Description

@spbsoluble

Deferred from #6 (review-findings-of-review-findings pass), flagged for triage before GA. Pre-existing behavior, not a regression introduced by #6.

Where

MarkMonitorClient.EnsureAuthenticatedAsync (markmonitor-caplugin/Client/MarkMonitorClient.cs:1130):

private async Task EnsureAuthenticatedAsync()
{
    if (!TokenNeedsRefresh()) return;

    await _authLock.WaitAsync();
    try
    {
        if (TokenNeedsRefresh())
        {
            _logger.LogDebug("No valid bearer token on hand - authenticating");
            await AuthenticateAsync();
        }
    }
    finally
    {
        _authLock.Release();
    }
}

Problem

Only the caller that actually wins the lock and calls AuthenticateAsync() logs anything. Callers
that were blocked on _authLock.WaitAsync() while another caller refreshed the token, then find
TokenNeedsRefresh() false once they acquire the lock, return silently. This makes it hard to tell
from logs alone how many concurrent operations were piled up waiting on a single re-authentication -
useful signal for diagnosing thundering-herd-style load against MarkMonitor's auth endpoint.

Suggested fix

Add a LogDebug/LogTrace in the else branch (i.e. when a waiter finds the token already
refreshed by someone else) noting that this call reused a token refreshed concurrently by another
caller.

Activity

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

    before-gaNeeds triage before GA release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions