Skip to content

Async_hooks use case: Detecting which async callback blocks the event loop #60169

@dsvictor94

Description

@dsvictor94

Affected URL(s)

https://nodejs.org/api/async_hooks.html

Description of the problem

We need a supported way to detect which async callback is blocking the event loop.
Currently, the only feasible approach is using async_hooks.createHook() and measuring the time spent between the before and after callbacks — but the docs recommend avoiding async_hooks.

Why this matters

As far as I know, there’s currently no alternative API that provides the same level of visibility.

Limitations of existing tools

  • perf_hooks.monitorEventLoopDelay can detect that lag is happening — but not what caused it.
  • CPU profiling can identify the blocking function, but only if we already know when the problem occurs so we can capture the profile at the right time.

Question

How can we migrate away from the async_hooks API for this use case, as recommended by the docs?
Is there a supported or planned alternative for attributing event loop delay to a specific async callback?

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions