Skip to content

Commit

Permalink
fix stack overflow when overriding HttpClientHandler.SendAsync() (#367)
Browse files Browse the repository at this point in the history
* add app that reproduces issue

* clean up comments

* update props to only include dll/so files

* add opcode parameter to DynamicMethodBuilder methods and use it when emitting IL

* add an additional argument to every wrapper method with the original call's opcode (value not used yet)

* split HttpMessageHandlerIntegration into separate wrappers, use new opcode argument to emit the correct IL

* keep using CALL for static method calls

* fix build error in AutomapperTest project

* fix integrations.json

* rename several variables for clarity

* include profiler pdb files in sample projects

* add test to ensure all wrapper methods have the last "int opCode" parameter
  • Loading branch information
lucaspimentel authored Jun 3, 2019
1 parent 98e83fa commit cf8326c
Show file tree
Hide file tree
Showing 26 changed files with 387 additions and 140 deletions.
19 changes: 19 additions & 0 deletions Datadog.Trace.sln
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.WebForms", "samples-aspnet\Samples.WebForms\Samples.WebForms.csproj", "{99A62CCF-8E7F-4D57-8383-D38C371C8087}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "reproductions", "reproductions", "{550AE553-2BBB-4021-B55A-137EF31A6B1F}"
ProjectSection(SolutionItems) = preProject
reproductions\Directory.Build.props = reproductions\Directory.Build.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExpenseItDemo", "reproductions\Reproduction.Wpf.ExpenseIt\ExpenseIt\ExpenseItDemo\ExpenseItDemo.csproj", "{D1729F17-99A5-45AF-AB38-72FA6ECCE609}"
EndProject
Expand All @@ -151,6 +154,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomapperTest", "reproduct
{C0C8D381-D6B9-4C76-9428-F40F2FA93A9A} = {C0C8D381-D6B9-4C76-9428-F40F2FA93A9A}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpMessageHandler.StackOverflow", "reproductions\HttpMessageHandler.StackOverflow\HttpMessageHandler.StackOverflow.csproj", "{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}"
ProjectSection(ProjectDependencies) = postProject
{C0C8D381-D6B9-4C76-9428-F40F2FA93A9A} = {C0C8D381-D6B9-4C76-9428-F40F2FA93A9A}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -501,6 +509,16 @@ Global
{2AD18622-9A02-41B4-915E-798BD64044D5}.Release|x64.Build.0 = Release|x64
{2AD18622-9A02-41B4-915E-798BD64044D5}.Release|x86.ActiveCfg = Release|x86
{2AD18622-9A02-41B4-915E-798BD64044D5}.Release|x86.Build.0 = Release|x86
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}.Debug|Any CPU.ActiveCfg = Debug|x86
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}.Debug|x64.ActiveCfg = Debug|x64
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}.Debug|x64.Build.0 = Debug|x64
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}.Debug|x86.ActiveCfg = Debug|x86
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}.Debug|x86.Build.0 = Debug|x86
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}.Release|Any CPU.ActiveCfg = Release|x86
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}.Release|x64.ActiveCfg = Release|x64
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}.Release|x64.Build.0 = Release|x64
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}.Release|x86.ActiveCfg = Release|x86
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -537,6 +555,7 @@ Global
{D1729F17-99A5-45AF-AB38-72FA6ECCE609} = {550AE553-2BBB-4021-B55A-137EF31A6B1F}
{AD119B05-A092-41AD-B68E-4AE2DB5A96D9} = {AA6F5582-3B71-49AC-AA39-8F7815AC46BE}
{2AD18622-9A02-41B4-915E-798BD64044D5} = {550AE553-2BBB-4021-B55A-137EF31A6B1F}
{F47F206E-4CCA-4AD0-AEBA-FD9F491E05EC} = {550AE553-2BBB-4021-B55A-137EF31A6B1F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F}
Expand Down
66 changes: 33 additions & 33 deletions integrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AdoNetIntegration",
"method": "ExecuteDbDataReader",
"signature": "00 02 1C 1C 08"
"signature": "00 03 1C 1C 08 08"
}
},
{
Expand All @@ -39,7 +39,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AdoNetIntegration",
"method": "ExecuteDbDataReader",
"signature": "00 02 1C 1C 08"
"signature": "00 03 1C 1C 08 08"
}
},
{
Expand All @@ -59,7 +59,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AdoNetIntegration",
"method": "ExecuteDbDataReaderAsync",
"signature": "00 03 1C 1C 08 1C"
"signature": "00 04 1C 1C 08 1C 08"
}
},
{
Expand All @@ -79,7 +79,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AdoNetIntegration",
"method": "ExecuteDbDataReaderAsync",
"signature": "00 03 1C 1C 08 1C"
"signature": "00 04 1C 1C 08 1C 08"
}
}
]
Expand All @@ -106,7 +106,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
"method": "BeforeAction",
"signature": "00 04 01 1C 1C 1C 1C"
"signature": "00 05 01 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -128,7 +128,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
"method": "AfterAction",
"signature": "00 04 01 1C 1C 1C 1C"
"signature": "00 05 01 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -150,7 +150,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
"method": "Rethrow",
"signature": "00 01 01 1C"
"signature": "00 02 01 1C 08"
}
}
]
Expand All @@ -177,7 +177,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetMvcIntegration",
"method": "BeginInvokeAction",
"signature": "00 05 1C 1C 1C 1C 1C 1C"
"signature": "00 06 1C 1C 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -199,7 +199,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetMvcIntegration",
"method": "EndInvokeAction",
"signature": "00 02 02 1C 1C"
"signature": "00 03 02 1C 1C 08"
}
}
]
Expand All @@ -224,7 +224,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetWebApi2Integration",
"method": "ExecuteAsync",
"signature": "00 03 1C 1C 1C 1C"
"signature": "00 04 1C 1C 1C 1C 08"
}
}
]
Expand All @@ -251,7 +251,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.ElasticsearchNet5Integration",
"method": "CallElasticsearch",
"signature": "10 01 02 1C 1C 1C"
"signature": "10 01 03 1C 1C 1C 08"
}
},
{
Expand All @@ -273,7 +273,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.ElasticsearchNet5Integration",
"method": "CallElasticsearchAsync",
"signature": "10 01 03 1C 1C 1C 1C"
"signature": "10 01 04 1C 1C 1C 1C 08"
}
}
]
Expand All @@ -300,7 +300,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.ElasticsearchNet6Integration",
"method": "CallElasticsearch",
"signature": "10 01 02 1C 1C 1C"
"signature": "10 01 03 1C 1C 1C 08"
}
},
{
Expand All @@ -322,7 +322,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.ElasticsearchNet6Integration",
"method": "CallElasticsearchAsync",
"signature": "10 01 03 1C 1C 1C 1C"
"signature": "10 01 04 1C 1C 1C 1C 08"
}
}
]
Expand All @@ -346,8 +346,8 @@
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.HttpMessageHandlerIntegration",
"method": "SendAsync",
"signature": "00 03 1C 1C 1C 1C"
"method": "HttpMessageHandler_SendAsync",
"signature": "00 04 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -366,8 +366,8 @@
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.HttpMessageHandlerIntegration",
"method": "SendAsync",
"signature": "00 03 1C 1C 1C 1C"
"method": "HttpClientHandler_SendAsync",
"signature": "00 04 1C 1C 1C 1C 08"
}
}
]
Expand All @@ -392,7 +392,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.MongoDbIntegration",
"method": "Execute",
"signature": "00 03 1C 1C 1C 1C"
"signature": "00 04 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -412,7 +412,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.MongoDbIntegration",
"method": "Execute",
"signature": "00 03 1C 1C 1C 1C"
"signature": "00 04 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -432,7 +432,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.MongoDbIntegration",
"method": "ExecuteAsync",
"signature": "00 03 1C 1C 1C 1C"
"signature": "00 04 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -452,7 +452,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.MongoDbIntegration",
"method": "ExecuteAsyncGeneric",
"signature": "00 03 1C 1C 1C 1C"
"signature": "00 04 1C 1C 1C 1C 08"
}
}
]
Expand All @@ -479,7 +479,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.ServiceStackRedisIntegration",
"method": "SendReceive",
"signature": "10 01 05 1E 00 1C 1D 1D 05 1C 1C 02"
"signature": "10 01 06 1E 00 1C 1D 1D 05 1C 1C 02 08"
}
}
]
Expand All @@ -506,7 +506,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.ConnectionMultiplexer",
"method": "ExecuteSyncImpl",
"signature": "10 01 04 1E 00 1C 1C 1C 1C"
"signature": "10 01 05 1E 00 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -528,7 +528,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.ConnectionMultiplexer",
"method": "ExecuteSyncImpl",
"signature": "10 01 04 1E 00 1C 1C 1C 1C"
"signature": "10 01 05 1E 00 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -550,7 +550,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.ConnectionMultiplexer",
"method": "ExecuteAsyncImpl",
"signature": "10 01 05 1C 1C 1C 1C 1C 1C"
"signature": "10 01 06 1C 1C 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -572,7 +572,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.ConnectionMultiplexer",
"method": "ExecuteAsyncImpl",
"signature": "10 01 05 1C 1C 1C 1C 1C 1C"
"signature": "10 01 06 1C 1C 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -594,7 +594,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch",
"method": "ExecuteAsync",
"signature": "10 01 04 1C 1C 1C 1C 1C"
"signature": "10 01 05 1C 1C 1C 1C 1C 08"
}
},
{
Expand All @@ -616,7 +616,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch",
"method": "ExecuteAsync",
"signature": "10 01 04 1C 1C 1C 1C 1C"
"signature": "10 01 05 1C 1C 1C 1C 1C 08"
}
}
]
Expand All @@ -641,7 +641,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.WcfIntegration",
"method": "HandleRequest",
"signature": "00 03 02 1C 1C 1C"
"signature": "00 04 02 1C 1C 1C 08"
}
}
]
Expand All @@ -666,7 +666,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.WebRequestIntegration",
"method": "GetResponse",
"signature": "00 01 1C 1C"
"signature": "00 02 1C 1C 08"
}
},
{
Expand All @@ -686,7 +686,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.WebRequestIntegration",
"method": "GetResponse",
"signature": "00 01 1C 1C"
"signature": "00 02 1C 1C 08"
}
},
{
Expand All @@ -706,7 +706,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.2.0.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.WebRequestIntegration",
"method": "GetResponseAsync",
"signature": "00 01 1C 1C"
"signature": "00 02 1C 1C 08"
}
}
]
Expand Down
14 changes: 0 additions & 14 deletions reproductions/AutomapperTest/AutomapperTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,4 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Datadog.Trace.ClrProfiler.Managed\Datadog.Trace.ClrProfiler.Managed.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\src\Datadog.Trace.ClrProfiler.Native\bin\$(Configuration)\$(Platform)\**"
CopyToOutputDirectory="Always"
CopyToPublishDirectory="Always"
Link="profiler-lib\%(RecursiveDir)\%(Filename)%(Extension)" />
<Content Include="..\..\integrations.json"
CopyToOutputDirectory="Always"
CopyToPublishDirectory="Always"
Link="profiler-lib\integrations.json" />
</ItemGroup>
</Project>
20 changes: 19 additions & 1 deletion reproductions/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
<Project>
<PropertyGroup>
<Platforms>x64;x86</Platforms>
<PlatformTarget>$(Platform)</PlatformTarget>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<ProfilerOutputDirectory>..\..\src\Datadog.Trace.ClrProfiler.Native\bin\$(Configuration)\$(Platform)</ProfilerOutputDirectory>
</PropertyGroup>
</Project>

<ItemGroup>
<ProjectReference Include="..\..\src\Datadog.Trace.ClrProfiler.Managed\Datadog.Trace.ClrProfiler.Managed.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="$(ProfilerOutputDirectory)\*.dll;$(ProfilerOutputDirectory)\*.so;$(ProfilerOutputDirectory)\*.pdb"
CopyToOutputDirectory="Always"
CopyToPublishDirectory="Always"
Link="profiler-lib\%(RecursiveDir)\%(Filename)%(Extension)" />
<Content Include="..\..\integrations.json"
CopyToOutputDirectory="Always"
CopyToPublishDirectory="Always"
Link="profiler-lib\integrations.json" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.2;netcoreapp2.1;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net461</TargetFrameworks>
<Platforms>x64;x86</Platforms>
<PlatformTarget>$(Platform)</PlatformTarget>
</PropertyGroup>

</Project>
Loading

0 comments on commit cf8326c

Please sign in to comment.