Skip to content

Deadlock: AssemblyResolve_ManagedProfilerDependencies should be moved out of Loader class #4269

Open
@lukeina2z

Description

@lukeina2z

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:

  1. The main thread enters the static constructor. The assembly resolve hook is installed, and additional initialization work begins, which may involve loading plugins.

  2. Some of the initialization code within the static constructor spawns a new thread.

  3. The main thread waits for the newly spawned worker thread to complete.

  4. The worker thread attempts to load a new assembly, triggering the AssemblyResolve_ManagedProfilerDependencies() hook.

  5. The hook is blocked because it requires access to the static context of the Loader class, which is still executing on the main thread.

  6. Deadlock occurs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions