Skip to content

[Profiler] Fix IpcServer for .NET Framework #6903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 2, 2025
Merged

Conversation

chrisnas
Copy link
Contributor

Summary of changes

Do not deallocate the instance of the IpcServer used in .NET Framework

Reason for change

Could randomly crash

Implementation details

The IpcServer instance is never deallocated and checks are made to avoid using it when/after the CLR shutdown

Test coverage

N/A

Other details

@chrisnas chrisnas requested a review from a team as a code owner April 28, 2025 15:45
@github-actions github-actions bot added area:profiler Issues related to the continous-profiler and removed identified-by:crashtracking labels Apr 28, 2025
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Apr 28, 2025

Datadog Report

All test runs 952104e 🔗

2 Total Test Services: 0 Failed, 2 Passed
1 with Regressions

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Performance Regressions Test Service View
dd-trace-dotnet 0 0 0 253811 2675 19h 11m 24.55s 1 Link
exploration_tests 0 0 0 22085 3 2m 9.57s 0 Link

⌛ Performance Regressions vs Default Branch (1)

  • Baseline_allocation - scenarios 2.18s (+29.71ms, +1%) - Details

@andrewlock
Copy link
Member

andrewlock commented Apr 28, 2025

Benchmarks Report for tracer 🐌

Benchmarks for #6903 compared to master:

  • 4 benchmarks are faster, with geometric mean 1.138
  • 1 benchmarks are slower, with geometric mean 1.148
  • 2 benchmarks have fewer allocations
  • 1 benchmarks have more allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.ActivityBenchmark - Same speed ✔️ More allocations ⚠️

More allocations ⚠️ in #6903

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.ActivityBenchmark.StartStopWithChild‑net472 6.15 KB 6.19 KB 44 B 0.72%

Fewer allocations 🎉 in #6903

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.ActivityBenchmark.StartStopWithChild‑net6.0 5.6 KB 5.56 KB -36 B -0.64%
Benchmarks.Trace.ActivityBenchmark.StartStopWithChild‑netcoreapp3.1 5.8 KB 5.73 KB -67 B -1.16%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartStopWithChild net6.0 8.25μs 144ns 1.44μs 0 0 0 5.6 KB
master StartStopWithChild netcoreapp3.1 9.83μs 99.8ns 988ns 0 0 0 5.8 KB
master StartStopWithChild net472 15.2μs 72.2ns 289ns 1.03 0.344 0.0688 6.15 KB
#6903 StartStopWithChild net6.0 7.11μs 18.2ns 63ns 0 0 0 5.56 KB
#6903 StartStopWithChild netcoreapp3.1 10.5μs 125ns 1.25μs 0 0 0 5.73 KB
#6903 StartStopWithChild net472 15.2μs 84.7ns 562ns 1.02 0.34 0.0679 6.19 KB
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 498μs 1.08μs 4.18μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 651μs 1.29μs 4.98μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 860μs 2.13μs 8.25μs 0 0 0 3.35 KB
#6903 WriteAndFlushEnrichedTraces net6.0 504μs 1.52μs 5.69μs 0 0 0 2.7 KB
#6903 WriteAndFlushEnrichedTraces netcoreapp3.1 661μs 1.35μs 4.85μs 0 0 0 2.7 KB
#6903 WriteAndFlushEnrichedTraces net472 861μs 616ns 2.31μs 0 0 0 3.35 KB
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendRequest net6.0 128μs 716ns 4.47μs 0 0 0 14.48 KB
master SendRequest netcoreapp3.1 142μs 811ns 6.07μs 0 0 0 17.28 KB
master SendRequest net472 0.0024ns 0.00101ns 0.00376ns 0 0 0 0 b
#6903 SendRequest net6.0 128μs 747ns 6.68μs 0 0 0 14.48 KB
#6903 SendRequest netcoreapp3.1 146μs 726ns 3.08μs 0 0 0 17.28 KB
#6903 SendRequest net472 0.0031ns 0.00146ns 0.00528ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 612μs 6.19μs 60μs 0 0 0 41.73 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 724μs 6.28μs 60.9μs 0 0 0 41.78 KB
master WriteAndFlushEnrichedTraces net472 857μs 5.02μs 49.9μs 7.81 0 0 53.47 KB
#6903 WriteAndFlushEnrichedTraces net6.0 557μs 2.89μs 13.9μs 0 0 0 41.7 KB
#6903 WriteAndFlushEnrichedTraces netcoreapp3.1 714μs 5.51μs 53.5μs 0 0 0 41.71 KB
#6903 WriteAndFlushEnrichedTraces net472 918μs 7.34μs 72.6μs 4.46 0 0 53.37 KB
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.3μs 1.02ns 3.82ns 0.013 0 0 1.03 KB
master ExecuteNonQuery netcoreapp3.1 1.9μs 4.54ns 17ns 0.00912 0 0 1.02 KB
master ExecuteNonQuery net472 2.08μs 3.4ns 12.7ns 0.154 0.0103 0 995 B
#6903 ExecuteNonQuery net6.0 1.27μs 2.32ns 8.69ns 0.0127 0 0 1.03 KB
#6903 ExecuteNonQuery netcoreapp3.1 1.77μs 4.2ns 15.7ns 0.00883 0 0 1.02 KB
#6903 ExecuteNonQuery net472 2.27μs 4.05ns 15.2ns 0.147 0.0113 0 995 B
Benchmarks.Trace.ElasticsearchBenchmark - Faster 🎉 Same allocations ✔️

Faster 🎉 in #6903

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync‑net6.0 1.130 1,315.39 1,164.36

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.17μs 0.581ns 2.1ns 0.0118 0 0 984 B
master CallElasticsearch netcoreapp3.1 1.52μs 1.08ns 4.19ns 0.00748 0 0 984 B
master CallElasticsearch net472 2.57μs 1.78ns 6.65ns 0.157 0 0 1 KB
master CallElasticsearchAsync net6.0 1.31μs 1.5ns 5.79ns 0.0131 0 0 960 B
master CallElasticsearchAsync netcoreapp3.1 1.62μs 1.29ns 4.99ns 0.00811 0 0 1.03 KB
master CallElasticsearchAsync net472 2.7μs 0.977ns 3.52ns 0.162 0 0 1.06 KB
#6903 CallElasticsearch net6.0 1.15μs 1.59ns 6.16ns 0.0115 0 0 984 B
#6903 CallElasticsearch netcoreapp3.1 1.55μs 1.8ns 6.74ns 0.00777 0 0 984 B
#6903 CallElasticsearch net472 2.57μs 1.66ns 6.2ns 0.156 0 0 1 KB
#6903 CallElasticsearchAsync net6.0 1.16μs 0.71ns 2.75ns 0.0117 0 0 960 B
#6903 CallElasticsearchAsync netcoreapp3.1 1.61μs 0.859ns 3.21ns 0.0081 0 0 1.03 KB
#6903 CallElasticsearchAsync net472 2.63μs 1.15ns 4.29ns 0.158 0 0 1.06 KB
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net6.0 1.28μs 0.574ns 2.15ns 0.0129 0 0 960 B
master ExecuteAsync netcoreapp3.1 1.7μs 2.25ns 8.41ns 0.00848 0 0 960 B
master ExecuteAsync net472 1.93μs 0.866ns 3.36ns 0.144 0 0 923 B
#6903 ExecuteAsync net6.0 1.16μs 0.911ns 3.53ns 0.0117 0 0 960 B
#6903 ExecuteAsync netcoreapp3.1 1.56μs 0.698ns 2.52ns 0.00789 0 0 960 B
#6903 ExecuteAsync net472 1.82μs 1.4ns 5.24ns 0.145 0 0 923 B
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendAsync net6.0 4.59μs 2.41ns 9.34ns 0.0228 0 0 2.32 KB
master SendAsync netcoreapp3.1 5.27μs 3.52ns 13.6ns 0.0262 0 0 2.86 KB
master SendAsync net472 7.49μs 5.18ns 18.7ns 0.485 0 0 3.13 KB
#6903 SendAsync net6.0 4.42μs 3.92ns 14.7ns 0.0224 0 0 2.32 KB
#6903 SendAsync netcoreapp3.1 5.29μs 4.67ns 18.1ns 0.0263 0 0 2.86 KB
#6903 SendAsync net472 7.55μs 2.8ns 10.9ns 0.491 0 0 3.13 KB
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 1.54μs 4.09ns 14.7ns 0.0235 0 0 1.71 KB
master EnrichedLog netcoreapp3.1 2.4μs 3.92ns 14.7ns 0.0119 0 0 1.71 KB
master EnrichedLog net472 2.75μs 5.93ns 23ns 0.259 0 0 1.64 KB
#6903 EnrichedLog net6.0 1.49μs 1.71ns 6.38ns 0.018 0 0 1.71 KB
#6903 EnrichedLog netcoreapp3.1 2.21μs 1.2ns 4.65ns 0.022 0 0 1.71 KB
#6903 EnrichedLog net472 2.76μs 2.08ns 8.07ns 0.248 0 0 1.64 KB
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 117μs 328ns 1.27μs 0 0 0 4.32 KB
master EnrichedLog netcoreapp3.1 126μs 469ns 1.76μs 0 0 0 4.32 KB
master EnrichedLog net472 159μs 683ns 2.64μs 0 0 0 4.51 KB
#6903 EnrichedLog net6.0 112μs 356ns 1.33μs 0 0 0 4.32 KB
#6903 EnrichedLog netcoreapp3.1 117μs 328ns 1.23μs 0 0 0 4.32 KB
#6903 EnrichedLog net472 150μs 144ns 538ns 0 0 0 4.51 KB
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 3.14μs 2.67ns 10.4ns 0.0313 0 0 2.26 KB
master EnrichedLog netcoreapp3.1 4.15μs 3.64ns 14.1ns 0.0206 0 0 2.26 KB
master EnrichedLog net472 4.82μs 3.13ns 11.7ns 0.314 0 0 2.09 KB
#6903 EnrichedLog net6.0 3.17μs 2.23ns 8.65ns 0.0317 0 0 2.26 KB
#6903 EnrichedLog netcoreapp3.1 4.3μs 3.06ns 11.4ns 0.0215 0 0 2.26 KB
#6903 EnrichedLog net472 4.9μs 2.83ns 11ns 0.318 0 0 2.09 KB
Benchmarks.Trace.RedisBenchmark - Faster 🎉 Same allocations ✔️

Faster 🎉 in #6903

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.RedisBenchmark.SendReceive‑net6.0 1.118 1,451.68 1,299.00

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendReceive net6.0 1.45μs 2.72ns 10.5ns 0.0143 0 0 1.15 KB
master SendReceive netcoreapp3.1 1.78μs 8.33ns 34.4ns 0.00898 0 0 1.15 KB
master SendReceive net472 2.19μs 9.79ns 37.9ns 0.184 0 0 1.16 KB
#6903 SendReceive net6.0 1.3μs 0.632ns 2.45ns 0.013 0 0 1.15 KB
#6903 SendReceive netcoreapp3.1 1.77μs 3.83ns 14.8ns 0.00881 0 0 1.15 KB
#6903 SendReceive net472 2.09μs 1.1ns 3.95ns 0.178 0 0 1.16 KB
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.66μs 2.35ns 9.1ns 0.0133 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 4.17μs 3.5ns 12.1ns 0.0209 0 0 1.69 KB
master EnrichedLog net472 4.55μs 3.8ns 14.2ns 0.32 0 0 2.08 KB
#6903 EnrichedLog net6.0 2.86μs 2.91ns 11.3ns 0.0143 0 0 1.64 KB
#6903 EnrichedLog netcoreapp3.1 3.89μs 2.08ns 7.77ns 0.0194 0 0 1.69 KB
#6903 EnrichedLog net472 4.33μs 2.6ns 10.1ns 0.323 0 0 2.08 KB
Benchmarks.Trace.SpanBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6903

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net6.0 1.148 409.66 470.22

Faster 🎉 in #6903

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net472 1.172 682.99 582.80
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑netcoreapp3.1 1.132 772.89 682.68

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 410ns 0.277ns 1.04ns 0.00812 0 0 584 B
master StartFinishSpan netcoreapp3.1 634ns 0.659ns 2.55ns 0.00635 0 0 584 B
master StartFinishSpan net472 683ns 0.185ns 0.692ns 0.0927 0 0 586 B
master StartFinishScope net6.0 480ns 0.522ns 2.02ns 0.00974 0 0 704 B
master StartFinishScope netcoreapp3.1 774ns 0.796ns 2.87ns 0.00751 0 0 704 B
master StartFinishScope net472 789ns 0.567ns 2.2ns 0.103 0 0 666 B
#6903 StartFinishSpan net6.0 471ns 0.284ns 1.1ns 0.00703 0 0 584 B
#6903 StartFinishSpan netcoreapp3.1 579ns 0.47ns 1.76ns 0.00583 0 0 584 B
#6903 StartFinishSpan net472 583ns 0.384ns 1.49ns 0.0904 0 0 586 B
#6903 StartFinishScope net6.0 496ns 0.253ns 0.948ns 0.00996 0 0 704 B
#6903 StartFinishScope netcoreapp3.1 682ns 0.619ns 2.23ns 0.00681 0 0 704 B
#6903 StartFinishScope net472 841ns 0.39ns 1.51ns 0.106 0 0 666 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net6.0 717ns 0.25ns 0.937ns 0.00757 0 0 704 B
master RunOnMethodBegin netcoreapp3.1 996ns 5.57ns 37.8ns 0.00492 0 0 704 B
master RunOnMethodBegin net472 1.12μs 0.755ns 2.83ns 0.101 0 0 666 B
#6903 RunOnMethodBegin net6.0 648ns 0.408ns 1.53ns 0.0097 0 0 704 B
#6903 RunOnMethodBegin netcoreapp3.1 897ns 1.21ns 4.38ns 0.0094 0 0 704 B
#6903 RunOnMethodBegin net472 1.05μs 0.828ns 3.1ns 0.105 0 0 666 B

@andrewlock
Copy link
Member

andrewlock commented Apr 28, 2025

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing the following branches/commits:

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 shown 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).

gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6903) - mean (70ms)  : 67, 73
     .   : milestone, 70,
    master - mean (69ms)  : 67, 71
     .   : milestone, 69,

    section CallTarget+Inlining+NGEN
    This PR (6903) - mean (1,012ms)  : 987, 1037
     .   : milestone, 1012,
    master - mean (1,009ms)  : 983, 1034
     .   : milestone, 1009,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6903) - mean (103ms)  : 101, 105
     .   : milestone, 103,
    master - mean (103ms)  : 101, 105
     .   : milestone, 103,

    section CallTarget+Inlining+NGEN
    This PR (6903) - mean (698ms)  : 683, 713
     .   : milestone, 698,
    master - mean (696ms)  : 673, 720
     .   : milestone, 696,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6903) - mean (90ms)  : 88, 92
     .   : milestone, 90,
    master - mean (89ms)  : 87, 91
     .   : milestone, 89,

    section CallTarget+Inlining+NGEN
    This PR (6903) - mean (656ms)  : 639, 674
     .   : milestone, 656,
    master - mean (652ms)  : 634, 670
     .   : milestone, 652,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6903) - mean (190ms)  : 186, 194
     .   : milestone, 190,
    master - mean (190ms)  : 186, 193
     .   : milestone, 190,

    section CallTarget+Inlining+NGEN
    This PR (6903) - mean (1,104ms)  : 1075, 1133
     .   : milestone, 1104,
    master - mean (1,112ms)  : 1082, 1141
     .   : milestone, 1112,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6903) - mean (270ms)  : 266, 274
     .   : milestone, 270,
    master - mean (269ms)  : 265, 272
     .   : milestone, 269,

    section CallTarget+Inlining+NGEN
    This PR (6903) - mean (881ms)  : 845, 917
     .   : milestone, 881,
    master - mean (881ms)  : 848, 913
     .   : milestone, 881,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6903) - mean (262ms)  : 256, 267
     .   : milestone, 262,
    master - mean (261ms)  : 256, 267
     .   : milestone, 261,

    section CallTarget+Inlining+NGEN
    This PR (6903) - mean (870ms)  : 840, 900
     .   : milestone, 870,
    master - mean (873ms)  : 843, 902
     .   : milestone, 873,

Loading

@@ -114,12 +114,13 @@ std::unique_ptr<IpcServer> IpcServer::StartAsync(
return nullptr;
}

auto server = std::make_unique<IpcServer>(
// the lifetime of this instance is the lifetime of the application (i.e. it won't be deleted to avoid random crashes)
auto server = new IpcServer(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have something with an equivalent lifetime where we could register this ? Or would we need a sync mechanism to request a shutdown ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the current implementation, the instance is destroyed AFTER the Shutdown is received from the CLR and we see a crash. Our guess is that the other native thread is then trying to access it

Copy link
Collaborator

@gleocadie gleocadie left a comment

Choose a reason for hiding this comment

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

🤞

@chrisnas chrisnas merged commit 6e13f5a into master May 2, 2025
132 of 136 checks passed
@chrisnas chrisnas deleted the chrisnas/fix_ipcserver branch May 2, 2025 08:15
@github-actions github-actions bot added this to the vNext-v3 milestone May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:profiler Issues related to the continous-profiler identified-by:crashtracking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants