Skip to content

Random timeout requiring managed identity to get new token #36715

@AnOdyssey

Description

@AnOdyssey

Bug description

Since about the beginning of August we've seen an increasing number of initial command timeouts before getting an new ManagedIdentityCredential.GetToken that resolves the failing command.

Image Image

Nothing has changes configuration wise.

Your code

We're using Aspire but with a pooled db context to enable global queries via a context factory

        builder.Services.AddPooledDbContextFactory<DatabaseContext>(o =>
        {
            o.UseSqlServer(builder.Configuration.GetConnectionString("sqldb"), b =>
            {
                b.EnableRetryOnFailure();
            });
            o.EnableSensitiveDataLogging(builder.Environment.IsDevelopment());
            o.EnableDetailedErrors(builder.Environment.IsDevelopment());
            o.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
        });



public class DatabaseContextScopedFactory(IDbContextFactory<DatabaseContext> pooledFactory, TenantScopedStore tenantScope) : IDbContextFactory<DatabaseContext>
{
    public DatabaseContext CreateDbContext()
    {
        var context = pooledFactory.CreateDbContext();
        context.TenantId = tenantScope.TenantId ?? Guid.Empty;
        return context;
    }
}



services.AddScoped<DatabaseContextScopedFactory>().AddScoped(sp =>sp.GetRequiredService<DatabaseContextScopedFactory>().CreateDbContext())

Stack traces

Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Unknown error 258

Verbose output


EF Core version

9.0.8

Database provider

Microsoft.EntityFrameworkCore.SqlServer

Target framework

.Net 9.0

Operating system

Azure app service, Linux docker

IDE

Rider

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions