Skip to content

TokenAcquirerFactory.GetDefaultInstance is not thread safe #3267

@jmprieur

Description

@jmprieur

Microsoft.Identity.Web Library

Microsoft.Identity.Web

Microsoft.Identity.Web version

3.x

Web app

Not Applicable

Web API

Not Applicable

Token cache serialization

Not Applicable

Description

TokenAcquirerFactory.GetDefaultInstance() and TokenAcquirerFactory.Build() should be thread safe.

Reproduction steps

Keep executing the code below from multiple threads. The code shouldn't be in a loop, as the race condition is specifically around the initialization of the singleton.
The program should be started again for the race condition to appear.
var instance = TokenAcquirerFactory.GetDefaultInstance();
if(instance.ServiceProvider == null)
{
instance.Build();
}

Error message

No response

Id Web logs

No response

Relevant code snippets

var instance = TokenAcquirerFactory.GetDefaultInstance();
if(instance.ServiceProvider == null)
{
    instance.Build();
}

Regression

No response

Expected behavior

TokenAcquirerFactory.GetDefaultInstance() and TokenAcquirerFactory.Build() should be thread safe.

Metadata

Metadata

Assignees

Labels

P1bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions