Add potential fix for duck typing derived types#8410
Conversation
zacharycmontoya
left a comment
There was a problem hiding this comment.
LGTM, thanks for looking into this!
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8410) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-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:
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 chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8410) - mean (75ms) : 73, 78
master - mean (76ms) : 72, 79
section Bailout
This PR (8410) - mean (80ms) : 78, 82
master - mean (81ms) : 79, 83
section CallTarget+Inlining+NGEN
This PR (8410) - mean (1,111ms) : 1055, 1167
master - mean (1,108ms) : 1070, 1145
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 (8410) - mean (119ms) : 115, 122
master - mean (119ms) : 116, 122
section Bailout
This PR (8410) - mean (120ms) : 118, 123
master - mean (121ms) : 118, 124
section CallTarget+Inlining+NGEN
This PR (8410) - mean (814ms) : 791, 836
master - mean (816ms) : 795, 837
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8410) - mean (105ms) : 102, 109
master - mean (105ms) : 101, 109
section Bailout
This PR (8410) - mean (106ms) : 103, 109
master - mean (106ms) : 102, 109
section CallTarget+Inlining+NGEN
This PR (8410) - mean (949ms) : 917, 981
master - mean (955ms) : 924, 985
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8410) - mean (105ms) : 101, 108
master - mean (104ms) : 101, 107
section Bailout
This PR (8410) - mean (105ms) : 102, 107
master - mean (105ms) : 103, 108
section CallTarget+Inlining+NGEN
This PR (8410) - mean (840ms) : 801, 878
master - mean (836ms) : 794, 878
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 (8410) - mean (218ms) : 210, 225
master - mean (214ms) : 209, 219
section Bailout
This PR (8410) - mean (223ms) : 218, 228
master - mean (218ms) : 213, 222
section CallTarget+Inlining+NGEN
This PR (8410) - mean (1,243ms) : 1194, 1291
master - mean (1,240ms) : 1196, 1284
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 (8410) - mean (310ms) : 302, 318
master - mean (309ms) : 302, 316
section Bailout
This PR (8410) - mean (312ms) : 304, 319
master - mean (311ms) : 304, 319
section CallTarget+Inlining+NGEN
This PR (8410) - mean (1,018ms) : 983, 1053
master - mean (1,016ms) : 990, 1043
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8410) - mean (306ms) : 298, 315
master - mean (304ms) : 297, 311
section Bailout
This PR (8410) - mean (306ms) : 300, 313
master - mean (304ms) : 297, 311
section CallTarget+Inlining+NGEN
This PR (8410) - mean (1,193ms) : 1155, 1231
master - mean (1,196ms) : 1154, 1237
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8410) - mean (301ms) : 294, 308
master - mean (303ms) : 295, 310
section Bailout
This PR (8410) - mean (304ms) : 298, 310
master - mean (303ms) : 299, 308
section CallTarget+Inlining+NGEN
This PR (8410) - mean (1,113ms) : 988, 1237
master - mean (1,111ms) : 982, 1240
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Summary of changes
Potentially fixes a
FieldAccessExceptionin some casesReason for change
We have seen stack traces like the following in production:
After a bunch of 🤖 noodling and testing (and based on @zacharycmontoya idea), proved that we can repro this stack (sort of, assuming inlining) if we derive from
System.Uri. The error happens because we applyIgnoresAccessChecksToAttributeto the target type (i.e. the derived type) during ducktyping, but it needs to be applied to thetargetField.DeclaringType.Implementation details
Updated the
UseDirectAccessTocalls to point to the type that "owns" the field, instead of the current instance.Test coverage
Added a test confirming the error, and then showing it passed
Other details
https://app.datadoghq.com/cases/APMLP-35