Skip to content

Fix .NET Framework startup deadlock from configBuilder sync-over-async#8498

Merged
NachoEchevarria merged 9 commits into
masterfrom
nacho/ConsoleFixDeadlock
Apr 24, 2026
Merged

Fix .NET Framework startup deadlock from configBuilder sync-over-async#8498
NachoEchevarria merged 9 commits into
masterfrom
nacho/ConsoleFixDeadlock

Conversation

@NachoEchevarria

@NachoEchevarria NachoEchevarria commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

Summary of changes

Move the AssemblyResolve handler off Startup onto a sibling class ManagedProfilerAssemblyResolver. .NET Framework only.

Reason for change

A customer is reporting that a console application is getting hung. They provided the console app code and a memory dump.

Affected: .NET Framework console apps / Windows services whose app.config has a <appSettings> configBuilder that performs sync-over-async work (concrete trigger: AzureAppConfigurationBuilder with DefaultAzureCredential and useAzureKeyVault="true").i

The process deadlocks before Main() runs:

  1. Main thread is inside Startup..cctor → reads ConfigurationManager.AppSettings → the configBuilder calls Task.Wait. Main thread blocked.
  2. The Task's async continuation runs on a ThreadPool thread, eventually calls Type.GetType(...) during credential-chain probing, firing AppDomain.AssemblyResolve.
  3. The CLR dispatches the handler. Because the handler is a static method on Startup, the CLR requires Startup..cctor to have completed before running it — it hasn't. The ThreadPool thread blocks on Startup..cctor; the main thread blocks on the Task. Classic .cctor × sync-over-async deadlock.

Any static member on Startup invoked from a ThreadPool thread during Startup..cctor has the same hazard, so the structural fix is to move the handler off Startup rather than try to remove specific .cctor-time work.

Implementation details

ManagedProfilerAssemblyResolver is a sibling class with a trivial .cctor. Startup..cctor seeds its ManagedProfilerDirectory property and subscribes OnAssemblyResolve before any ThreadPool work can be scheduled; the resolver is fully initialized by the time a ThreadPool thread dispatches the handler, so dispatch doesn't wait on anything.

Startup.AssemblyName was widened from private const to internal const so the sibling class can reference it. Const strings are inlined at compile time, so this is not a runtime type-init dependency. This change does not affect the automatic version bump mechanisms.

.NET Core paths are unchanged — configBuilders is a .NET Framework-only feature, so the equivalent trigger doesn't exist there.

Test coverage

Verified against a local repro mirroring the customer scenario (configBuilder with DefaultAzureCredential + useAzureKeyVault + mock Azure App Config returning a Key Vault reference):

  • Pre-fix: process hangs before printing Starting Main().
  • Post-fix: process prints Starting Main() and continues normally.

Customer-provided memory dump stacks match the pre-fix local repro stacks, confirming it's the same deadlock.

Other details

@NachoEchevarria NachoEchevarria changed the title Nacho/console fix deadlock Fix .NET Framework startup deadlock from configBuilder sync-over-async Apr 22, 2026
Investigation-only notes with workstation-specific paths; PR description
carries the relevant context.
@NachoEchevarria NachoEchevarria added type:bug area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) labels Apr 22, 2026
@pr-commenter

pr-commenter Bot commented Apr 22, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-04-22 15:15:02

Comparing candidate commit 862f3a0 in PR branch nacho/ConsoleFixDeadlock with baseline commit 34902b0 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 27 metrics, 0 unstable metrics, 60 known flaky benchmarks, 27 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net6.0

  • 🟩 throughput [+8474.278op/s; +12365.821op/s] or [+7.123%; +10.394%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 execution_time [+306.150ms; +308.653ms] or [+151.922%; +153.165%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • 🟥 execution_time [+380.885ms; +383.804ms] or [+300.923%; +303.229%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 execution_time [+398.630ms; +401.819ms] or [+352.772%; +355.595%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net472

  • 🟥 allocated_mem [+1.308KB; +1.308KB] or [+27.529%; +27.541%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net6.0

  • 🟥 allocated_mem [+471 bytes; +472 bytes] or [+9.977%; +9.987%]
  • 🟩 execution_time [-16.048ms; -11.879ms] or [-7.495%; -5.548%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody netcoreapp3.1

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+27.502%; +27.510%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net472

  • 🟥 allocated_mem [+1.307KB; +1.307KB] or [+105.746%; +105.759%]
  • 🟥 throughput [-247226.815op/s; -244542.129op/s] or [-25.243%; -24.969%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0

  • 🟥 allocated_mem [+471 bytes; +472 bytes] or [+38.558%; +38.566%]
  • 🟩 execution_time [-26.212ms; -16.911ms] or [-11.689%; -7.541%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+105.292%; +105.304%]
  • 🟥 throughput [-130011.851op/s; -113644.273op/s] or [-18.680%; -16.328%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net6.0

  • 🟩 throughput [+11104.491op/s; +14078.823op/s] or [+7.066%; +8.958%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody netcoreapp3.1

  • 🟩 throughput [+7606.866op/s; +10241.250op/s] or [+6.060%; +8.158%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net6.0

  • 🟩 throughput [+517434.358op/s; +531519.863op/s] or [+17.253%; +17.723%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody netcoreapp3.1

  • 🟩 execution_time [-19.088ms; -14.733ms] or [-8.799%; -6.791%]
  • 🟩 throughput [+205588.452op/s; +259187.800op/s] or [+8.160%; +10.288%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net472

  • 🟥 execution_time [+299.929ms; +300.598ms] or [+149.864%; +150.199%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net6.0

  • 🟥 execution_time [+299.315ms; +302.456ms] or [+150.945%; +152.529%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs netcoreapp3.1

  • 🟥 execution_time [+299.577ms; +302.124ms] or [+150.904%; +152.187%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net472

  • 🟥 execution_time [+297.059ms; +298.058ms] or [+145.904%; +146.394%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0

  • 🟥 execution_time [+294.021ms; +295.948ms] or [+143.736%; +144.678%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1

  • 🟥 execution_time [+300.901ms; +302.352ms] or [+150.390%; +151.115%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net6.0

  • 🟥 execution_time [+25.986µs; +55.064µs] or [+5.960%; +12.629%]
  • 🟥 throughput [-258.229op/s; -131.376op/s] or [-11.227%; -5.712%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net6.0

  • 🟥 execution_time [+23.575µs; +47.218µs] or [+7.526%; +15.074%]
  • 🟥 throughput [-438.100op/s; -239.178op/s] or [-13.657%; -7.456%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net472

  • 🟥 execution_time [+299.478ms; +300.148ms] or [+149.470%; +149.805%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net6.0

  • unstable execution_time [+333.163ms; +377.640ms] or [+361.995%; +410.321%]
  • 🟩 throughput [+1022.376op/s; +1169.833op/s] or [+8.401%; +9.613%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest netcoreapp3.1

  • unstable execution_time [+236.481ms; +280.840ms] or [+179.558%; +213.239%]
  • 🟩 throughput [+650.028op/s; +850.392op/s] or [+6.293%; +8.232%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • unstable execution_time [+396.613ms; +474.685ms] or [+182.359%; +218.256%]
  • 🟥 throughput [-576.780op/s; -521.884op/s] or [-52.262%; -47.288%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • unstable execution_time [+203.352ms; +336.574ms] or [+86.660%; +143.434%]
  • 🟥 throughput [-748.267op/s; -664.639op/s] or [-49.910%; -44.332%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 execution_time [+334.899ms; +342.188ms] or [+200.308%; +204.668%]
  • 🟥 throughput [-402.674op/s; -367.354op/s] or [-28.038%; -25.578%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0

  • 🟩 execution_time [-83.941µs; -56.422µs] or [-7.785%; -5.233%]
  • 🟩 throughput [+54.027op/s; +86.104op/s] or [+5.825%; +9.284%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472

  • 🟥 execution_time [+302.613ms; +303.828ms] or [+152.390%; +153.002%]
  • 🟩 throughput [+15676.307op/s; +17548.967op/s] or [+5.044%; +5.647%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net6.0

  • 🟥 execution_time [+303.404ms; +305.716ms] or [+152.036%; +153.195%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch netcoreapp3.1

  • 🟥 execution_time [+300.890ms; +304.288ms] or [+151.154%; +152.862%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472

  • 🟥 execution_time [+302.693ms; +303.993ms] or [+152.002%; +152.655%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net6.0

  • 🟥 execution_time [+298.756ms; +300.962ms] or [+147.722%; +148.812%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync netcoreapp3.1

  • 🟥 execution_time [+301.761ms; +305.279ms] or [+152.946%; +154.729%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472

  • 🟥 execution_time [+301.838ms; +303.172ms] or [+151.495%; +152.165%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net6.0

  • 🟥 execution_time [+298.638ms; +300.549ms] or [+148.844%; +149.796%]
  • 🟩 throughput [+51280.551op/s; +57363.956op/s] or [+10.183%; +11.391%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1

  • 🟥 execution_time [+300.178ms; +302.804ms] or [+149.336%; +150.642%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net6.0

  • 🟩 execution_time [-15.384ms; -11.641ms] or [-7.154%; -5.413%]
  • 🟩 throughput [+25557.695op/s; +32212.300op/s] or [+7.011%; +8.837%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net472

  • unstable execution_time [+5.072µs; +46.217µs] or [+1.253%; +11.416%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net6.0

  • 🟩 allocated_mem [-26.535KB; -26.515KB] or [-9.679%; -9.672%]
  • unstable execution_time [-56.655µs; -5.026µs] or [-11.198%; -0.993%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0

  • 🟥 execution_time [+5.774µs; +9.745µs] or [+13.648%; +23.034%]
  • 🟥 throughput [-4483.479op/s; -2724.825op/s] or [-18.874%; -11.471%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark netcoreapp3.1

  • unstable execution_time [-15.104µs; -8.004µs] or [-23.433%; -12.418%]
  • 🟩 throughput [+2129.170op/s; +3603.241op/s] or [+13.063%; +22.107%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472

  • 🟥 execution_time [+302.223ms; +303.207ms] or [+152.760%; +153.258%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net6.0

  • 🟥 execution_time [+301.970ms; +304.423ms] or [+153.702%; +154.950%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+300.875ms; +303.425ms] or [+150.625%; +151.902%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net6.0

  • 🟩 throughput [+32964.036op/s; +35441.893op/s] or [+6.239%; +6.708%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net472

  • 🟥 execution_time [+301.863ms; +303.401ms] or [+150.452%; +151.218%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net6.0

  • 🟥 execution_time [+302.601ms; +303.926ms] or [+151.952%; +152.617%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+303.363ms; +305.830ms] or [+153.846%; +155.098%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net472

  • 🟥 execution_time [+299.905ms; +300.537ms] or [+149.594%; +149.909%]
  • 🟩 throughput [+61173294.197op/s; +61439379.550op/s] or [+44.550%; +44.744%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0

  • 🟥 execution_time [+423.652ms; +427.196ms] or [+526.887%; +531.294%]
  • 🟩 throughput [+890.067op/s; +1073.670op/s] or [+6.881%; +8.300%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1

  • 🟥 execution_time [+299.556ms; +300.461ms] or [+149.412%; +149.863%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net6.0

  • 🟩 throughput [+80260.142op/s; +90941.175op/s] or [+7.494%; +8.491%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope netcoreapp3.1

  • 🟩 throughput [+49854.352op/s; +69541.137op/s] or [+5.771%; +8.049%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net6.0

  • 🟩 throughput [+76711.643op/s; +107451.554op/s] or [+5.938%; +8.317%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan netcoreapp3.1

  • 🟩 throughput [+75951.550op/s; +84373.786op/s] or [+7.543%; +8.380%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net6.0

  • 🟩 throughput [+37200.751op/s; +50549.494op/s] or [+6.755%; +9.179%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes netcoreapp3.1

  • 🟩 throughput [+30515.192op/s; +40037.156op/s] or [+6.830%; +8.962%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net6.0

  • 🟩 throughput [+67182.646op/s; +84348.316op/s] or [+7.506%; +9.424%]

Known flaky benchmarks without significant changes:

  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net472
  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net472
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog netcoreapp3.1
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark netcoreapp3.1
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net472
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net472
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive netcoreapp3.1
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net472
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin netcoreapp3.1

@NachoEchevarria
NachoEchevarria marked this pull request as ready for review April 23, 2026 08:23
@NachoEchevarria
NachoEchevarria requested review from a team as code owners April 23, 2026 08:23
@dd-trace-dotnet-ci-bot

Copy link
Copy Markdown

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8498) and master.

✅ No regressions detected - check the details below

Full Metrics Comparison

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration75.06 ± (74.75 - 75.30) ms74.21 ± (74.23 - 74.77) ms-1.1%
.NET Framework 4.8 - Bailout
duration79.03 ± (78.91 - 79.46) ms77.02 ± (76.90 - 77.26) ms-2.5%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1074.32 ± (1073.42 - 1080.45) ms1079.53 ± (1077.68 - 1086.43) ms+0.5%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms22.93 ± (22.86 - 22.99) ms22.42 ± (22.38 - 22.46) ms-2.2%
process.time_to_main_ms87.46 ± (87.15 - 87.77) ms84.12 ± (83.92 - 84.32) ms-3.8%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.84 ± (10.84 - 10.84) MB10.92 ± (10.91 - 10.92) MB+0.7%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms22.40 ± (22.36 - 22.44) ms22.80 ± (22.75 - 22.86) ms+1.8%✅⬆️
process.time_to_main_ms86.07 ± (85.85 - 86.28) ms88.44 ± (88.11 - 88.77) ms+2.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.93 ± (10.93 - 10.94) MB10.94 ± (10.94 - 10.95) MB+0.1%✅⬆️
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms213.52 ± (212.66 - 214.38) ms212.00 ± (211.02 - 212.98) ms-0.7%
process.time_to_main_ms525.90 ± (524.65 - 527.15) ms526.91 ± (525.55 - 528.26) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed47.90 ± (47.88 - 47.92) MB47.87 ± (47.84 - 47.91) MB-0.1%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%
.NET 6 - Baseline
process.internal_duration_ms21.44 ± (21.39 - 21.49) ms21.50 ± (21.44 - 21.56) ms+0.3%✅⬆️
process.time_to_main_ms74.15 ± (73.89 - 74.41) ms75.35 ± (75.03 - 75.66) ms+1.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.60 ± (10.60 - 10.60) MB10.64 ± (10.64 - 10.64) MB+0.4%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms21.11 ± (21.07 - 21.14) ms21.10 ± (21.07 - 21.13) ms-0.0%
process.time_to_main_ms73.83 ± (73.64 - 74.02) ms74.00 ± (73.81 - 74.19) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.71 ± (10.71 - 10.71) MB10.75 ± (10.75 - 10.75) MB+0.4%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms384.18 ± (382.10 - 386.27) ms381.57 ± (379.58 - 383.57) ms-0.7%
process.time_to_main_ms529.41 ± (527.99 - 530.83) ms526.13 ± (524.88 - 527.38) ms-0.6%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.21 ± (49.18 - 49.24) MB49.36 ± (49.34 - 49.39) MB+0.3%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.3%
.NET 8 - Baseline
process.internal_duration_ms19.73 ± (19.67 - 19.78) ms19.47 ± (19.42 - 19.52) ms-1.3%
process.time_to_main_ms73.85 ± (73.57 - 74.13) ms72.87 ± (72.65 - 73.10) ms-1.3%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.68 ± (7.67 - 7.69) MB7.67 ± (7.67 - 7.67) MB-0.1%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.87 ± (19.82 - 19.92) ms19.81 ± (19.75 - 19.87) ms-0.3%
process.time_to_main_ms76.12 ± (75.83 - 76.40) ms76.14 ± (75.85 - 76.43) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.72 ± (7.72 - 7.72) MB7.73 ± (7.73 - 7.74) MB+0.2%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms303.51 ± (301.29 - 305.73) ms301.34 ± (299.31 - 303.37) ms-0.7%
process.time_to_main_ms487.99 ± (486.86 - 489.11) ms487.20 ± (486.15 - 488.26) ms-0.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.66 ± (36.61 - 36.71) MB36.70 ± (36.65 - 36.76) MB+0.1%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)-0.4%

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration206.24 ± (205.81 - 206.93) ms201.40 ± (200.82 - 202.03) ms-2.3%
.NET Framework 4.8 - Bailout
duration207.98 ± (207.62 - 208.60) ms204.77 ± (204.29 - 205.34) ms-1.5%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1195.48 ± (1198.14 - 1205.90) ms1180.27 ± (1179.47 - 1186.78) ms-1.3%
.NET Core 3.1 - Baseline
process.internal_duration_ms197.32 ± (196.84 - 197.80) ms195.15 ± (194.66 - 195.65) ms-1.1%
process.time_to_main_ms85.79 ± (85.51 - 86.06) ms84.55 ± (84.29 - 84.80) ms-1.4%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.04 ± (16.03 - 16.06) MB15.99 ± (15.98 - 16.01) MB-0.3%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-1.2%
.NET Core 3.1 - Bailout
process.internal_duration_ms197.91 ± (197.36 - 198.47) ms195.56 ± (195.03 - 196.09) ms-1.2%
process.time_to_main_ms87.75 ± (87.47 - 88.03) ms85.71 ± (85.46 - 85.95) ms-2.3%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.12 ± (16.10 - 16.13) MB16.04 ± (16.03 - 16.06) MB-0.5%
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)-0.6%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms391.32 ± (390.17 - 392.47) ms385.34 ± (384.11 - 386.58) ms-1.5%
process.time_to_main_ms532.59 ± (531.20 - 533.98) ms523.15 ± (521.73 - 524.57) ms-1.8%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed57.83 ± (57.67 - 57.99) MB57.32 ± (57.14 - 57.50) MB-0.9%
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)-0.5%
.NET 6 - Baseline
process.internal_duration_ms202.23 ± (201.75 - 202.72) ms200.16 ± (199.61 - 200.70) ms-1.0%
process.time_to_main_ms74.66 ± (74.42 - 74.91) ms73.39 ± (73.16 - 73.63) ms-1.7%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.23 ± (16.21 - 16.25) MB16.30 ± (16.28 - 16.32) MB+0.4%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.1%
.NET 6 - Bailout
process.internal_duration_ms202.83 ± (202.30 - 203.36) ms198.91 ± (198.39 - 199.43) ms-1.9%
process.time_to_main_ms75.94 ± (75.68 - 76.20) ms74.40 ± (74.19 - 74.62) ms-2.0%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.32 ± (16.30 - 16.34) MB16.40 ± (16.38 - 16.43) MB+0.5%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-0.6%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms594.92 ± (592.24 - 597.61) ms595.09 ± (592.20 - 597.97) ms+0.0%✅⬆️
process.time_to_main_ms532.10 ± (530.91 - 533.29) ms526.66 ± (525.50 - 527.82) ms-1.0%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed60.90 ± (60.80 - 60.99) MB60.96 ± (60.86 - 61.06) MB+0.1%✅⬆️
runtime.dotnet.threads.count31 ± (31 - 31)31 ± (31 - 31)+0.1%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms200.88 ± (200.36 - 201.41) ms198.24 ± (197.75 - 198.74) ms-1.3%
process.time_to_main_ms73.65 ± (73.39 - 73.91) ms72.99 ± (72.73 - 73.25) ms-0.9%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.61 ± (11.59 - 11.62) MB11.67 ± (11.65 - 11.69) MB+0.6%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (18 - 19)-0.5%
.NET 8 - Bailout
process.internal_duration_ms200.55 ± (200.05 - 201.05) ms197.07 ± (196.54 - 197.61) ms-1.7%
process.time_to_main_ms74.90 ± (74.67 - 75.13) ms73.89 ± (73.68 - 74.11) ms-1.3%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.64 ± (11.62 - 11.65) MB11.71 ± (11.70 - 11.73) MB+0.7%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)19 ± (19 - 19)-1.4%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms527.53 ± (522.45 - 532.62) ms520.19 ± (516.36 - 524.02) ms-1.4%
process.time_to_main_ms490.59 ± (489.52 - 491.65) ms485.33 ± (484.26 - 486.40) ms-1.1%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed50.34 ± (50.28 - 50.40) MB50.23 ± (50.19 - 50.27) MB-0.2%
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)-0.3%
Comparison explanation

Execution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

Duration charts
FakeDbCommand (.NET Framework 4.8)
gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8498) - mean (74ms)  : 71, 78
    master - mean (75ms)  : 71, 79

    section Bailout
    This PR (8498) - mean (77ms)  : 75, 79
    master - mean (79ms)  : 75, 83

    section CallTarget+Inlining+NGEN
    This PR (8498) - mean (1,082ms)  : 1037, 1127
    master - mean (1,077ms)  : 1027, 1127

Loading
FakeDbCommand (.NET Core 3.1)
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8498) - mean (113ms)  : 110, 117
    master - mean (118ms)  : 112, 123

    section Bailout
    This PR (8498) - mean (118ms)  : 111, 125
    master - mean (115ms)  : 112, 119

    section CallTarget+Inlining+NGEN
    This PR (8498) - mean (777ms)  : 757, 798
    master - mean (776ms)  : 751, 801

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8498) - mean (103ms)  : 97, 110
    master - mean (102ms)  : 96, 108

    section Bailout
    This PR (8498) - mean (101ms)  : 98, 104
    master - mean (101ms)  : 98, 104

    section CallTarget+Inlining+NGEN
    This PR (8498) - mean (936ms)  : 899, 974
    master - mean (941ms)  : 899, 983

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8498) - mean (100ms)  : 95, 105
    master - mean (101ms)  : 97, 105

    section Bailout
    This PR (8498) - mean (104ms)  : 99, 109
    master - mean (104ms)  : 99, 109

    section CallTarget+Inlining+NGEN
    This PR (8498) - mean (821ms)  : 789, 852
    master - mean (822ms)  : 778, 867

Loading
HttpMessageHandler (.NET Framework 4.8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8498) - mean (201ms)  : 192, 211
    master - mean (206ms)  : 198, 215

    section Bailout
    This PR (8498) - mean (205ms)  : 197, 212
    master - mean (208ms)  : 202, 214

    section CallTarget+Inlining+NGEN
    This PR (8498) - mean (1,183ms)  : 1128, 1238
    master - mean (1,202ms)  : 1145, 1259

Loading
HttpMessageHandler (.NET Core 3.1)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8498) - mean (289ms)  : 278, 300
    master - mean (293ms)  : 283, 302

    section Bailout
    This PR (8498) - mean (290ms)  : 279, 301
    master - mean (295ms)  : 283, 307

    section CallTarget+Inlining+NGEN
    This PR (8498) - mean (944ms)  : 909, 979
    master - mean (961ms)  : 930, 992

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8498) - mean (283ms)  : 270, 295
    master - mean (286ms)  : 275, 296

    section Bailout
    This PR (8498) - mean (282ms)  : 274, 290
    master - mean (287ms)  : 277, 297

    section CallTarget+Inlining+NGEN
    This PR (8498) - mean (1,150ms)  : 1107, 1194
    master - mean (1,156ms)  : 1115, 1196

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8498) - mean (281ms)  : 273, 290
    master - mean (285ms)  : 273, 297

    section Bailout
    This PR (8498) - mean (282ms)  : 270, 293
    master - mean (286ms)  : 275, 297

    section CallTarget+Inlining+NGEN
    This PR (8498) - mean (1,038ms)  : 985, 1091
    master - mean (1,049ms)  : 973, 1126

Loading

@andrewlock andrewlock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify:

  • Previously the problem was that the AssemblyResolve would fire as part of the app.config loading, but would be blocked because the tracer initializes here, in the Startup static constructor. As the ctor isn't finished, the AssemblyResolve handler can't run.
  • With the change, we're still initializing the tracer in the same place, and we're still running the same assembly resolve code, the only difference is that because the handler isn't defined on Startup, the handler can run, so no deadlock

This seems like a problem that could theoretically occur in .NET Core too (although it won't be exactly the same because we don't load app.config). Is there any reason we shouldn't do the same thing for .NET Core as we did for .NET Framework, for consistency and safety? 🤔

@NachoEchevarria

Copy link
Copy Markdown
Collaborator Author

Just to clarify:

  • Previously the problem was that the AssemblyResolve would fire as part of the app.config loading, but would be blocked because the tracer initializes here, in the Startup static constructor. As the ctor isn't finished, the AssemblyResolve handler can't run.
  • With the change, we're still initializing the tracer in the same place, and we're still running the same assembly resolve code, the only difference is that because the handler isn't defined on Startup, the handler can run, so no deadlock

This seems like a problem that could theoretically occur in .NET Core too (although it won't be exactly the same because we don't load app.config). Is there any reason we shouldn't do the same thing for .NET Core as we did for .NET Framework, for consistency and safety? 🤔

Agreed the same pattern should apply on .NET Core to avoid similar deadlocks. I can add that to a subsequent PR, if that's ok, to keep this PR focused on the escalation resolution.

@bouwkast bouwkast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@NachoEchevarria
NachoEchevarria merged commit 8339c77 into master Apr 24, 2026
140 checks passed
@NachoEchevarria
NachoEchevarria deleted the nacho/ConsoleFixDeadlock branch April 24, 2026 07:55
@github-actions github-actions Bot added this to the vNext-v3 milestone Apr 24, 2026
NachoEchevarria added a commit that referenced this pull request Apr 27, 2026
Follow-up to #8498. No known .NET Core trigger today; defense-in-depth
for consistency.

## Summary of changes

Mirror the .NET Framework fix from #8498 on .NET Core. Move the
`AppDomain.AssemblyResolve` and `AssemblyLoadContext.Default.Resolving`
handlers, plus the assembly cache and `DependencyLoadContext`, off
`Startup` onto `ManagedProfilerAssemblyResolver`.

## Reason for change

The mechanism behind #8498 — "invoking a static member requires the
declaring type's `.cctor` to have completed" — is runtime-generic; only
the trigger (`<appSettings>` configBuilder) was Framework-specific. On
.NET Core both `AppDomain.AssemblyResolve` (static method on `Startup`)
and `AssemblyLoadContext.Default.Resolving` (lambda compiled to a static
method on `Startup`) have the same latent hazard if anything in the
`.cctor` chain ever does sync-over-async.

## Implementation details

Same shape as #8498:

- New `ManagedProfilerAssemblyResolver.NetCore.cs` with the handlers,
`ResolveAssembly`, `DependencyLoadContext`, cache, and a
`PopulateAssemblyCache` entry point.
- `Startup.NetCore.cs` slimmed — `ComputeTfmDirectory` delegates cache
population to the resolver.
- `Startup.cs`: `#if NETFRAMEWORK` conditionals removed; both TFMs
subscribe through the resolver, and the ALC `Resolving` lambda now
points at `OnAssemblyLoadContextResolving`. `LoadAssembly` fallback uses
the resolver unconditionally.

Both `OnAssemblyResolve` and `OnAssemblyLoadContextResolving` wrap
`ResolveAssembly` in a `try/catch` that logs via `StartupLogger` and
returns `null`, matching the .NET Framework resolver. Without this, a
throw from `LoadFromAssemblyPath` (e.g. `BadImageFormatException`,
`FileLoadException`) would propagate into whoever triggered the resolve
— often a credential-chain probe expecting `null` on miss — breaking
their fallback logic.

`Startup..cctor` seeds
`ManagedProfilerAssemblyResolver.ManagedProfilerDirectory` before
subscribing, triggering the resolver's trivial `.cctor` up-front so
ThreadPool dispatches don't wait on anything.

## Test coverage

No new tests — the deadlock is theoretical on .NET Core. Existing
loader/instrumentation tests exercise the new dispatch path.

## Other details

None.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) identified-by:customer type:bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants