Skip to content

Fix authentication provider lifecycle race condition in ExtHostAuthentication #256289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 16, 2025

Fixes a race condition in the authentication provider lifecycle where session operations could fail if the provider was disposed during execution.

Problem

The failing test "session operations during provider lifecycle changes" exposed a race condition where:

  1. A session creation operation starts (getSession)
  2. The provider is disposed while the session creation is in progress
  3. The disposal operation runs first and removes the provider from the registry
  4. When the session creation operation executes, it can't find the provider and throws:
    Error: Unable to find authentication provider with handle: lifecycle-test
    

Root Cause

Both disposal and session operations are queued using the same SequencerByKey with the provider ID. The disposal operation removes the provider from the _authenticationProviders map before the session operation can access it.

Solution

Modified the authentication operation methods to capture provider references before queuing operations:

// Before (race condition possible)
$createSession(providerId: string, scopes: string[], options: AuthenticationProviderSessionOptions) {
    return this._providerOperations.queue(providerId, async () => {
        const providerData = this._authenticationProviders.get(providerId); // Could be null if disposed
        if (providerData) {
            return await providerData.provider.createSession(scopes, options);
        }
        throw new Error(`Unable to find authentication provider with handle: ${providerId}`);
    });
}

// After (race condition fixed)
$createSession(providerId: string, scopes: string[], options: AuthenticationProviderSessionOptions) {
    // Capture provider reference before queuing
    const providerData = this._authenticationProviders.get(providerId);
    if (!providerData) {
        throw new Error(`Unable to find authentication provider with handle: ${providerId}`);
    }

    return this._providerOperations.queue(providerId, async () => {
        // Use captured reference - works even if provider is disposed
        return await providerData.provider.createSession(scopes, options);
    });
}

Changes Made

  • Updated $createSession, $removeSession, and $getSessions methods in extHostAuthentication.ts
  • Each method now captures the provider reference before queuing the operation
  • Operations can complete successfully even if the provider is disposed during execution
  • Error handling remains unchanged - invalid provider IDs still fail immediately

Behavior Change

  • Before: Operations could fail if provider was disposed between queuing and execution
  • After: Operations that start with a valid provider will complete successfully, even if provider is disposed during execution

This ensures the test expectation is met: "The session creation should complete successfully even if we dispose during the operation"

Fixes #255118.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Capture provider references before queuing operations to ensure ongoing
operations can complete even if the provider is disposed during execution.

This fixes the race condition where:
1. A session operation starts and gets queued
2. Provider disposal is triggered and gets queued
3. Disposal runs first and removes provider from registry
4. Session operation fails to find provider

The fix captures provider data before queuing so operations proceed
with their captured reference even if registry is modified.

Co-authored-by: TylerLeonhardt <[email protected]>
@Copilot Copilot AI changed the title [WIP] Error: Unable to find authentication provider with handle: lifecycle-test Fix authentication provider lifecycle race condition in ExtHostAuthentication Jul 16, 2025
@Copilot Copilot AI requested a review from TylerLeonhardt July 16, 2025 17:00
Copilot finished work on behalf of TylerLeonhardt July 16, 2025 17: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.

Flaky ExtHostAuthentication test
2 participants