Skip to content

Fix EH clause sort to handle try-in-handler nesting#8428

Draft
bouwkast wants to merge 5 commits intomasterfrom
steven/attempt-fix-invalid-program-exception
Draft

Fix EH clause sort to handle try-in-handler nesting#8428
bouwkast wants to merge 5 commits intomasterfrom
steven/attempt-fix-invalid-program-exception

Conversation

@bouwkast
Copy link
Copy Markdown
Collaborator

@bouwkast bouwkast commented Apr 8, 2026

Generated mostly by Claude

Summary of changes

Fix incorrect EH clause ordering in ILRewriter::Export() that caused InvalidProgramException when instrumenting methods with try blocks nested inside handler regions.

Reason for change

When we instrument a method, the IL rewriter may insert try/catch blocks inside the handler of an existing try/catch (e.g., debugger inserting EndMethod(SetException) inside an async state machine's outer catch, or CallTarget instrumentation wrapping handler logic). ECMA-335 II.19 requires such nested clauses to appear before the clause whose region encloses them in the EH table.

The existing sort comparator only checked try-in-try containment:

return a.m_pTryBegin->m_offset > b.m_pTryBegin->m_offset &&
       a.m_pTryEnd->m_offset < b.m_pTryEnd->m_offset;

Because the inserted clause's try region starts after the outer clause's try region ends, this check returns false. The clause stays in its appended position -- after the outer clause -- violating ECMA-335. The CLR validates EH table ordering on JIT and rejects the method with InvalidProgramException.

The comparator also violated strict weak ordering required by std::sort (transitivity of incomparability fails for sibling clauses adjacent to a nesting relationship), making its behavior undefined.

Implementation details

Replaced the inline std::sort with ILRewriter::SortEHClauses, a new static method that:

  1. Computes a nesting depth for each clause: the number of other clauses whose try or handler region strictly contains this clause's try region. This correctly detects both try-in-try and try-in-handler nesting per ECMA-335 II.19.

  2. Sorts by (depth descending, try offset ascending), which is a total order and therefore satisfies strict weak ordering. Deeper-nested clauses sort first, satisfying the ECMA-335 requirement.

The method is extracted as a static to make it directly unit-testable without requiring ICorProfilerInfo. Internal allocations use std::unique_ptr to prevent memory leaks if an allocation fails.

Test coverage

Added ILRewriterEHSortTest in Datadog.Tracer.Native.Tests with 8 Google Test cases covering:

  • Try-in-try nesting (existing behavior preserved)
  • Try-in-handler nesting (the core bug)
  • Sibling clauses (no nesting constraint, ordered by offset)
  • Three-level deep nesting
  • The exact debugger async middleware topology: 2 original Roslyn clauses + 3 debugger-inserted clauses, verifying the EndMethod(SetException) clause is ordered before the outer clause whose handler contains it
  • Single and zero clause edge cases

The OldComparatorFailsMiddlewareScenario test applies the original comparator inline against the middleware topology and asserts it produces the wrong ordering, confirming the bug is real and the new tests would catch a regression.

Added integration test in tracer/test/test-applications/integrations/Samples.TraceAnnotations/ExtremeExceptionHandling.cs that reproduces the crash. Without the fix, the test causes a CLR fatal exception.

Other details

Symptom: System.InvalidProgramException: Common Language Runtime detected an invalid program thrown on any instrumented method whose EH table contains try-in-handler nesting. Originally observed on async middleware InvokeAsync methods with Exception Replay enabled, but affects any instrumentation path that goes through ILRewriter::Export().

Linked to APMS-19196

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Apr 8, 2026

Benchmarks

Benchmark execution time: 2026-04-10 16:42:25

Comparing candidate commit 6b6b9a4 in PR branch steven/attempt-fix-invalid-program-exception with baseline commit 58f22e8 in branch master.

Found 29 performance improvements and 40 performance regressions! Performance is the same for 211 metrics, 8 unstable metrics.

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 ----------------------------------'

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

  • 🟩 throughput [+9548.628op/s; +11764.432op/s] or [+8.026%; +9.888%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 execution_time [+310.313ms; +312.244ms] or [+153.988%; +154.947%]

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

  • 🟥 execution_time [+383.460ms; +385.932ms] or [+302.957%; +304.910%]

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

  • 🟥 execution_time [+399.125ms; +400.869ms] or [+353.210%; +354.754%]

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

  • 🟩 throughput [+7020.530op/s; +10689.119op/s] or [+5.125%; +7.802%]

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

  • 🟩 execution_time [-25.684ms; -20.320ms] or [-11.454%; -9.062%]
  • 🟩 throughput [+94044.821op/s; +118851.855op/s] or [+10.047%; +12.697%]

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

  • 🟩 throughput [+80818.848op/s; +104600.396op/s] or [+11.612%; +15.029%]

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

  • 🟩 throughput [+9575.256op/s; +12510.799op/s] or [+6.093%; +7.960%]

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

  • 🟩 throughput [+334472.210op/s; +368839.400op/s] or [+11.153%; +12.299%]

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

  • 🟩 execution_time [-18.174ms; -13.750ms] or [-8.377%; -6.338%]
  • 🟩 throughput [+171719.940op/s; +227626.727op/s] or [+6.816%; +9.035%]

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

  • 🟥 execution_time [+300.389ms; +300.923ms] or [+150.094%; +150.361%]

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

  • 🟥 execution_time [+298.337ms; +301.534ms] or [+150.452%; +152.064%]

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

  • 🟥 execution_time [+299.562ms; +302.086ms] or [+150.896%; +152.168%]

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

  • 🟥 execution_time [+297.909ms; +298.802ms] or [+146.321%; +146.760%]

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

  • 🟥 execution_time [+293.783ms; +294.930ms] or [+143.620%; +144.180%]

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

  • 🟥 execution_time [+300.637ms; +301.889ms] or [+150.258%; +150.884%]

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

  • 🟥 execution_time [+23.102µs; +50.059µs] or [+5.299%; +11.481%]
  • 🟥 throughput [-243.374op/s; -122.248op/s] or [-10.581%; -5.315%]

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

  • 🟥 execution_time [+27.424µs; +51.122µs] or [+8.755%; +16.321%]
  • 🟥 throughput [-469.477op/s; -270.270op/s] or [-14.635%; -8.425%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net472

  • 🟥 execution_time [+299.785ms; +300.491ms] or [+149.624%; +149.976%]

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

  • 🟥 execution_time [+416.064ms; +422.385ms] or [+452.071%; +458.938%]
  • 🟩 throughput [+1205.948op/s; +1340.391op/s] or [+9.909%; +11.014%]

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

  • 🟩 throughput [+722.025op/s; +922.288op/s] or [+6.990%; +8.928%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 throughput [-534.901op/s; -471.858op/s] or [-48.467%; -42.755%]

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

  • 🟥 throughput [-746.267op/s; -662.807op/s] or [-49.776%; -44.209%]

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

  • 🟥 execution_time [+345.433ms; +355.347ms] or [+206.609%; +212.539%]
  • 🟥 throughput [-420.184op/s; -384.657op/s] or [-29.257%; -26.783%]

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

  • 🟩 execution_time [-178.341µs; -140.258µs] or [-9.034%; -7.105%]
  • 🟩 throughput [+40.713op/s; +50.970op/s] or [+8.037%; +10.062%]

scenario:Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery net472

  • 🟥 throughput [-23191.121op/s; -19323.832op/s] or [-6.532%; -5.443%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472

  • 🟥 execution_time [+302.404ms; +303.410ms] or [+152.285%; +152.791%]

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

  • 🟥 execution_time [+301.289ms; +302.371ms] or [+150.977%; +151.519%]
  • 🟩 throughput [+45266.743op/s; +49316.963op/s] or [+7.137%; +7.775%]

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

  • 🟥 execution_time [+301.699ms; +305.120ms] or [+151.561%; +153.280%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472

  • 🟥 execution_time [+302.800ms; +304.724ms] or [+152.056%; +153.022%]

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

  • 🟥 execution_time [+298.693ms; +300.194ms] or [+147.690%; +148.432%]

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

  • 🟥 execution_time [+300.640ms; +304.226ms] or [+152.377%; +154.195%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472

  • 🟥 execution_time [+301.799ms; +302.946ms] or [+151.476%; +152.052%]

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

  • 🟥 execution_time [+296.347ms; +298.983ms] or [+147.702%; +149.016%]
  • 🟩 throughput [+59952.851op/s; +65420.563op/s] or [+11.905%; +12.990%]

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

  • 🟥 execution_time [+300.411ms; +303.589ms] or [+149.452%; +151.033%]

scenario:Benchmarks.Trace.HttpClientBenchmark.SendAsync net472

  • 🟥 throughput [-5761.819op/s; -5063.798op/s] or [-6.578%; -5.781%]

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

  • 🟩 allocated_mem [-18.656KB; -18.635KB] or [-6.805%; -6.798%]

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

  • 🟩 throughput [+99.344op/s; +253.816op/s] or [+5.676%; +14.501%]

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

  • 🟥 throughput [-5474.955op/s; -3622.521op/s] or [-23.048%; -15.250%]

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

  • 🟩 throughput [+2016.093op/s; +3444.264op/s] or [+12.369%; +21.132%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472

  • 🟥 execution_time [+299.678ms; +302.643ms] or [+151.474%; +152.972%]

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

  • 🟥 execution_time [+304.499ms; +307.867ms] or [+154.989%; +156.703%]

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

  • 🟥 execution_time [+299.461ms; +301.354ms] or [+149.917%; +150.865%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net472

  • 🟥 throughput [-26477.882op/s; -23444.148op/s] or [-7.330%; -6.490%]

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

  • 🟩 throughput [+51690.348op/s; +55979.220op/s] or [+9.784%; +10.596%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net472

  • 🟥 execution_time [+298.726ms; +300.432ms] or [+148.888%; +149.738%]

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

  • 🟥 execution_time [+301.125ms; +303.168ms] or [+151.210%; +152.237%]

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

  • 🟥 execution_time [+302.786ms; +305.195ms] or [+153.554%; +154.776%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net472

  • 🟥 execution_time [+299.550ms; +300.164ms] or [+149.417%; +149.723%]
  • 🟩 throughput [+54901288.039op/s; +62548025.776op/s] or [+39.983%; +45.551%]

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

  • 🟩 throughput [+1033.824op/s; +1199.149op/s] or [+7.992%; +9.270%]

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

  • 🟥 execution_time [+299.077ms; +300.035ms] or [+149.173%; +149.651%]
  • 🟩 throughput [+18122197.279op/s; +19068456.892op/s] or [+8.027%; +8.446%]

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

  • 🟩 throughput [+89904.419op/s; +101443.105op/s] or [+8.394%; +9.471%]

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

  • 🟩 throughput [+48303.976op/s; +67554.697op/s] or [+5.591%; +7.819%]

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

  • 🟩 throughput [+84967.580op/s; +114987.256op/s] or [+6.577%; +8.900%]

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

  • 🟩 throughput [+92101.518op/s; +100014.464op/s] or [+9.147%; +9.933%]

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

  • 🟩 throughput [+52067.984op/s; +56960.378op/s] or [+9.455%; +10.343%]

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

  • 🟩 throughput [+24274.776op/s; +34122.632op/s] or [+5.433%; +7.638%]

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

  • 🟩 throughput [+74958.066op/s; +92858.306op/s] or [+8.375%; +10.375%]

@bouwkast
Copy link
Copy Markdown
Collaborator Author

bouwkast commented Apr 8, 2026

Closing this as I just thought it would be easier to share this as a PR form than not, if this is valuable can always pick it back up but we don't know if this actually solves anything.

@bouwkast bouwkast closed this Apr 8, 2026
@bouwkast bouwkast reopened this Apr 9, 2026
@dd-trace-dotnet-ci-bot
Copy link
Copy Markdown

dd-trace-dotnet-ci-bot bot commented Apr 9, 2026

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8428) 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.71 ± (76.45 - 77.76) ms71.38 ± (71.44 - 71.78) ms-5.7%
.NET Framework 4.8 - Bailout
duration80.64 ± (80.78 - 82.06) ms75.71 ± (75.55 - 75.87) ms-6.1%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1162.14 ± (1153.33 - 1169.39) ms1097.24 ± (1104.18 - 1122.10) ms-5.6%
.NET Core 3.1 - Baseline
process.internal_duration_ms24.77 ± (24.68 - 24.87) ms23.17 ± (23.12 - 23.22) ms-6.5%
process.time_to_main_ms98.96 ± (98.64 - 99.28) ms86.18 ± (85.99 - 86.37) ms-12.9%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.93 ± (10.93 - 10.94) MB10.93 ± (10.92 - 10.93) MB-0.1%
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms23.97 ± (23.80 - 24.14) ms22.78 ± (22.74 - 22.82) ms-4.9%
process.time_to_main_ms100.23 ± (99.85 - 100.62) ms86.20 ± (86.02 - 86.38) ms-14.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.96 ± (10.96 - 10.96) MB10.95 ± (10.95 - 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_ms232.32 ± (231.20 - 233.44) ms229.50 ± (228.49 - 230.50) ms-1.2%
process.time_to_main_ms538.23 ± (536.65 - 539.81) ms524.12 ± (523.04 - 525.20) ms-2.6%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.35 ± (48.32 - 48.37) MB48.39 ± (48.36 - 48.41) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.0%
.NET 6 - Baseline
process.internal_duration_ms21.49 ± (21.43 - 21.54) ms20.97 ± (20.93 - 21.00) ms-2.4%
process.time_to_main_ms75.12 ± (74.85 - 75.39) ms72.26 ± (72.11 - 72.42) ms-3.8%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.61 - 10.62) MB10.64 ± (10.64 - 10.64) MB+0.2%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms21.38 ± (21.34 - 21.42) ms20.97 ± (20.94 - 21.00) ms-1.9%
process.time_to_main_ms76.10 ± (75.87 - 76.32) ms73.65 ± (73.47 - 73.83) ms-3.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.72 ± (10.72 - 10.72) MB10.76 ± (10.75 - 10.76) MB+0.4%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms382.55 ± (380.66 - 384.44) ms383.37 ± (381.40 - 385.33) ms+0.2%✅⬆️
process.time_to_main_ms530.63 ± (529.60 - 531.67) ms520.90 ± (520.01 - 521.79) ms-1.8%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.93 ± (49.90 - 49.96) MB50.00 ± (49.98 - 50.03) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.1%
.NET 8 - Baseline
process.internal_duration_ms19.74 ± (19.70 - 19.79) ms19.11 ± (19.08 - 19.15) ms-3.2%
process.time_to_main_ms73.92 ± (73.71 - 74.12) ms71.37 ± (71.22 - 71.52) ms-3.5%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.68 ± (7.67 - 7.69) MB7.67 ± (7.66 - 7.67) MB-0.2%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.56 ± (19.52 - 19.60) ms19.17 ± (19.12 - 19.21) ms-2.0%
process.time_to_main_ms74.36 ± (74.14 - 74.59) ms72.13 ± (71.97 - 72.28) ms-3.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.76 ± (7.75 - 7.77) MB7.72 ± (7.71 - 7.72) MB-0.5%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms303.58 ± (301.23 - 305.93) ms305.65 ± (303.31 - 307.99) ms+0.7%✅⬆️
process.time_to_main_ms490.98 ± (489.93 - 492.03) ms479.00 ± (478.20 - 479.80) ms-2.4%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed37.07 ± (37.05 - 37.10) MB37.10 ± (37.08 - 37.13) MB+0.1%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)+0.9%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration194.28 ± (194.08 - 194.86) ms193.50 ± (193.39 - 194.10) ms-0.4%
.NET Framework 4.8 - Bailout
duration197.53 ± (197.39 - 198.05) ms196.34 ± (196.23 - 196.78) ms-0.6%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1154.87 ± (1156.18 - 1162.45) ms1147.71 ± (1149.01 - 1154.79) ms-0.6%
.NET Core 3.1 - Baseline
process.internal_duration_ms189.07 ± (188.64 - 189.51) ms188.02 ± (187.68 - 188.37) ms-0.6%
process.time_to_main_ms81.68 ± (81.44 - 81.91) ms81.05 ± (80.83 - 81.27) ms-0.8%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.11 ± (16.08 - 16.13) MB16.09 ± (16.06 - 16.12) MB-0.1%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)+0.2%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms189.08 ± (188.74 - 189.42) ms187.49 ± (187.22 - 187.77) ms-0.8%
process.time_to_main_ms83.07 ± (82.91 - 83.23) ms82.32 ± (82.17 - 82.46) ms-0.9%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.13 ± (16.10 - 16.16) MB16.17 ± (16.15 - 16.20) MB+0.2%✅⬆️
runtime.dotnet.threads.count21 ± (20 - 21)21 ± (20 - 21)-0.2%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms398.91 ± (397.41 - 400.41) ms394.59 ± (393.29 - 395.90) ms-1.1%
process.time_to_main_ms514.97 ± (513.40 - 516.53) ms510.04 ± (508.86 - 511.21) ms-1.0%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed59.24 ± (59.18 - 59.31) MB59.00 ± (58.83 - 59.17) MB-0.4%
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)+0.1%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms194.71 ± (194.28 - 195.15) ms192.12 ± (191.79 - 192.44) ms-1.3%
process.time_to_main_ms71.38 ± (71.19 - 71.57) ms70.23 ± (70.06 - 70.40) ms-1.6%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.38 ± (16.35 - 16.41) MB15.96 ± (15.81 - 16.12) MB-2.5%
runtime.dotnet.threads.count19 ± (19 - 19)18 ± (18 - 19)-3.1%
.NET 6 - Bailout
process.internal_duration_ms195.08 ± (194.71 - 195.45) ms190.92 ± (190.69 - 191.15) ms-2.1%
process.time_to_main_ms72.70 ± (72.56 - 72.84) ms71.14 ± (71.05 - 71.23) ms-2.1%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.40 ± (16.34 - 16.46) MB16.03 ± (15.88 - 16.18) MB-2.3%
runtime.dotnet.threads.count20 ± (20 - 20)19 ± (19 - 19)-5.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms601.42 ± (598.77 - 604.07) ms597.28 ± (594.68 - 599.88) ms-0.7%
process.time_to_main_ms515.46 ± (514.38 - 516.54) ms513.04 ± (512.27 - 513.82) ms-0.5%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed61.79 ± (61.70 - 61.88) MB61.72 ± (61.63 - 61.81) MB-0.1%
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)-0.1%
.NET 8 - Baseline
process.internal_duration_ms193.11 ± (192.65 - 193.57) ms189.36 ± (189.08 - 189.63) ms-1.9%
process.time_to_main_ms71.23 ± (71.03 - 71.43) ms69.72 ± (69.55 - 69.88) ms-2.1%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.71 ± (11.69 - 11.73) MB11.74 ± (11.69 - 11.79) MB+0.3%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-1.1%
.NET 8 - Bailout
process.internal_duration_ms189.90 ± (189.56 - 190.23) ms188.89 ± (188.66 - 189.13) ms-0.5%
process.time_to_main_ms71.31 ± (71.19 - 71.42) ms70.74 ± (70.67 - 70.80) ms-0.8%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.82 ± (11.79 - 11.84) MB11.83 ± (11.78 - 11.88) MB+0.1%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.2%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms516.74 ± (513.84 - 519.64) ms518.96 ± (516.24 - 521.67) ms+0.4%✅⬆️
process.time_to_main_ms474.42 ± (473.61 - 475.24) ms470.65 ± (469.96 - 471.34) ms-0.8%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed50.74 ± (50.71 - 50.77) MB50.69 ± (50.66 - 50.71) MB-0.1%
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)-0.2%
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 (8428) - mean (72ms)  : 69, 74
    master - mean (77ms)  : 67, 87

    section Bailout
    This PR (8428) - mean (76ms)  : 74, 77
    master - mean (81ms)  : 72, 91

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (1,113ms)  : 983, 1244
    master - mean (1,161ms)  : 1045, 1278

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 (8428) - mean (117ms)  : 113, 120
    master - mean (132ms)  : 126, 139

    section Bailout
    This PR (8428) - mean (116ms)  : 113, 119
    master - mean (133ms)  : 126, 139

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (792ms)  : 765, 818
    master - mean (807ms)  : 769, 844

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8428) - mean (99ms)  : 97, 102
    master - mean (104ms)  : 98, 109

    section Bailout
    This PR (8428) - mean (101ms)  : 98, 103
    master - mean (104ms)  : 100, 108

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (932ms)  : 902, 963
    master - mean (944ms)  : 903, 985

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

    section Bailout
    This PR (8428) - mean (99ms)  : 97, 101
    master - mean (102ms)  : 98, 106

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (813ms)  : 780, 846
    master - mean (825ms)  : 788, 862

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 (8428) - mean (194ms)  : 190, 197
    master - mean (194ms)  : 190, 199

    section Bailout
    This PR (8428) - mean (197ms)  : 194, 199
    master - mean (198ms)  : 195, 201

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (1,152ms)  : 1111, 1193
    master - mean (1,159ms)  : 1114, 1204

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 (8428) - mean (278ms)  : 273, 283
    master - mean (279ms)  : 273, 285

    section Bailout
    This PR (8428) - mean (278ms)  : 276, 281
    master - mean (281ms)  : 275, 286

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (932ms)  : 911, 953
    master - mean (942ms)  : 918, 966

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8428) - mean (271ms)  : 267, 275
    master - mean (274ms)  : 267, 282

    section Bailout
    This PR (8428) - mean (270ms)  : 267, 274
    master - mean (276ms)  : 272, 280

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (1,140ms)  : 1102, 1178
    master - mean (1,146ms)  : 1118, 1175

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8428) - mean (269ms)  : 265, 273
    master - mean (274ms)  : 268, 281

    section Bailout
    This PR (8428) - mean (269ms)  : 267, 271
    master - mean (271ms)  : 267, 275

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (1,025ms)  : 982, 1067
    master - mean (1,024ms)  : 984, 1064

Loading

@anna-git anna-git added area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) labels Apr 10, 2026
## Summary of changes

This reproduces the crash [described in this
README](https://github.com/DataDog/dd-trace-dotnet/blob/82cc4cf0e29478fd2fdc41afdf764a2abf662199/repro/APMS-19196/README.md)
on linux x64 arch.

Aim is to merge to #8428
First tested it's crashing on master 
<img width="2830" height="851" alt="image"
src="https://github.com/user-attachments/assets/96e882fa-308e-44b6-8116-c93c7d5b7bb2"
/>


## Reason for change

## Implementation details

## Test coverage

## Other details
<!-- Fixes #{issue} -->


<!--  ⚠️ Note:

Where possible, please obtain 2 approvals prior to merging. Unless
CODEOWNERS specifies otherwise, for external teams it is typically best
to have one review from a team member, and one review from apm-dotnet.
Trivial changes do not require 2 reviews.

MergeQueue is NOT enabled in this repository. If you have write access
to the repo, the PR has 1-2 approvals (see above), and all of the
required checks have passed, you can use the Squash and Merge button to
merge the PR. If you don't have write access, or you need help, reach
out in the #apm-dotnet channel in Slack.
-->
@github-actions
Copy link
Copy Markdown
Contributor

Snapshots difference summary

The following differences have been observed in committed snapshots. It is meant to help the reviewer.
The diff is simplistic, so please check some files anyway while we improve it.

3 occurrences of :

+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_62,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
+    Service: Samples.TraceAnnotations,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }

3 occurrences of :

+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_62,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
+    Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }

3 occurrences of :

+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_62,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
+    Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }

@bouwkast bouwkast added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label Apr 10, 2026
Add original index as final tiebreaker so std::sort does not
reorder catch/filter handlers that share the same try region.
Without this, multiple catch blocks for the same try can be
silently swapped, changing which handler the runtime evaluates
first.
Extract IsProperlyContained helper, use explicit types, add braces
on all control flow, and use named variables in the sort comparator
to match surrounding native code style.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants