Prevent AssemblyResolve Event from causing infinite recursion on mscorlib resource lookup#573
Conversation
| // to enter the AssemblyResolve event when searching for resources | ||
| // in its satellite assemblies. Exit early so we don't cause | ||
| // infinite recursion. | ||
| if (string.Equals(assemblyName, "mscorlib.resources", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
This is the fix for .NET Framework. Since the fix is commented out, we will see a failure in CI, at which point I will re-enable the fix.
There was a problem hiding this comment.
Would it be safer to check for any resource assembly (*.resources)?
There was a problem hiding this comment.
No other resource assembly will cause this recursion issue so I think it's helpful to single out this particular issue. We could add another check for resources assemblies in general as a small optimization if you'd like, but it wouldn't necessarily provide any more safety.
There was a problem hiding this comment.
Should we not limit our checks to only our dependencies?
There was a problem hiding this comment.
In other words, wouldn't this be resolved by short-circuiting when the assembly name is not one of those WE need?
…IntegrationTests.SmokeTests to actually run them in CI
…rofiler.IntegrationTests.SmokeTests to actually run them in CI" This reverts commit bea87c7.
…rash to linux build.
…nger timing out in the Windows CI.
…rlib resource lookup (DataDog#573) Modifies the AssemblyResolve event handler in the Datadog.Trace.ClrProfiler.Managed.Loader assembly to eagerly exit if the requested assembly is `mscorlib.resources` or `System.Private.CoreLib.resources` on .NET Framework and .NET Core, respectively. This fixes a known issue where on a non-US locale, a lookup of an `mscorlib` resource invokes the AssemblyResolve event and our event handler causes infinite recursion and the .NET application to crash. This occurred because, in processing the event, the event handler would make a method call to `File.Exists`, which triggers yet another AssemblyResolve event for `mscorlib` and the cycle continues. Even though this has only been demonstrated to occur on .NET Framework and should not occur on .NET Core 2.0+ (see https://github.com/dotnet/coreclr/issues/12668), proactively guard against AssemblyResolve events for `System.Private.CoreLib.resources` as well.
…rlib resource lookup (#573) Modifies the AssemblyResolve event handler in the Datadog.Trace.ClrProfiler.Managed.Loader assembly to eagerly exit if the requested assembly is `mscorlib.resources` or `System.Private.CoreLib.resources` on .NET Framework and .NET Core, respectively. This fixes a known issue where on a non-US locale, a lookup of an `mscorlib` resource invokes the AssemblyResolve event and our event handler causes infinite recursion and the .NET application to crash. This occurred because, in processing the event, the event handler would make a method call to `File.Exists`, which triggers yet another AssemblyResolve event for `mscorlib` and the cycle continues. Even though this has only been demonstrated to occur on .NET Framework and should not occur on .NET Core 2.0+ (see https://github.com/dotnet/coreclr/issues/12668), proactively guard against AssemblyResolve events for `System.Private.CoreLib.resources` as well.
Changes proposed in this pull request:
Modifies the AssemblyResolve event handler in the Datadog.Trace.ClrProfiler.Managed.Loader assembly to eagerly exit if the requested assembly is
mscorlib.resourcesorSystem.Private.CoreLib.resourceson .NET Framework and .NET Core, respectively.This fixes a known issue where on a non-US locale, a lookup of an
mscorlibresource invokes the AssemblyResolve event and our event handler causes infinite recursion and the .NET application to crash. This occurred because, in processing the event, the event handler would make a method call toFile.Exists, which triggers yet another AssemblyResolve event formscorliband the cycle continues. Even though this has only been demonstrated to occur on .NET Framework and should not occur on .NET Core 2.0+ (see https://github.com/dotnet/coreclr/issues/12668), proactively guard against AssemblyResolve events forSystem.Private.CoreLib.resourcesas well.@DataDog/apm-dotnet