Skip to content

Deadlock when configuring ApplicationInsightsServiceOptions #88390

@jonathan-vogel-siemens

Description

@jonathan-vogel-siemens

Description

When adding ApplicationInsights to an ASP.NET core web app's IServiceCollection via AddApplicationInsightsTelemetry() and adding a call to ConfigureOptions<ConfigureApplicationInsightsServiceOptions>() to configure ApplicationInsightsServiceOptions, we are experiencing a deadlock.

Sample code

Program.cs:

services.ConfigureOptions<ConfigureApplicationInsightsServiceOptions>();
services.AddApplicationInsightsTelemetry();

ConfigureApplicationInsightsServiceOptions.cs:

public class ConfigureApplicationInsightsServiceOptions : IConfigureOptions<ApplicationInsightsServiceOptions>
    {
        public ConfigureApplicationInsightsServiceOptions(
            SecretClient secretClient)
        {
            SecretClient = secretClient;
        }

        public SecretClient SecretClient { get; }

        public void Configure(ApplicationInsightsServiceOptions options)
        {
            KeyVaultSecret secret = SecretClient.GetSecret("appinsights");
            options.ConnectionString = secret.Value;
        }
    }

Reproduction Steps

  1. Call ConfigureOptions<ConfigureApplicationInsightsServiceOptions>() on the IServiceCollection as shown in the description
  2. Call AddApplicationInsightsTelemetry() on the IServiceCollection as shown in the description

Or see here: https://github.com/jonathan-vogel-siemens/IssueRepro88390

Expected behavior

ConfigureApplicationInsightsServiceOptions.Configure should be invoked when the WebApplicationBuilder is building

Actual behavior

Deadlock. See running tasks here:

image

Somehow it is blocking at

Regression?

Seems like it is a regression. A similar method (yielding the same deadlock) is documented here, from 2021: https://www.uveta.io/categories/blog/unclutter-startup-cs/#Application-Insights

Known Workarounds

No response

Configuration

  • .NET 6.0
  • Windows
  • x64
  • Plain ASP.NET Razor Web App

Other information

No response

Metadata

Metadata

Labels

area-Extensions-DependencyInjectionin-prThere is an active PR which will close this issue when it is mergedneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions