Description
This issue concerns the OpenTelemetry.AutoInstrumentation.Loader.Loader class. It has a static constructor, which means that while the static constructor is executing, no threads can enter any of the class's static methods. This can lead to a deadlock due to the presence of an assembly loading hook: AssemblyResolve_ManagedProfilerDependencies().
Deadlock Scenario:
-
The main thread enters the static constructor. The assembly resolve hook is installed, and additional initialization work begins, which may involve loading plugins.
-
Some of the initialization code within the static constructor spawns a new thread.
-
The main thread waits for the newly spawned worker thread to complete.
-
The worker thread attempts to load a new assembly, triggering the AssemblyResolve_ManagedProfilerDependencies() hook.
-
The hook is blocked because it requires access to the static context of the Loader class, which is still executing on the main thread.
-
Deadlock occurs.