Skip to content

[async_hooks] Cannot properly propagate context in its current state #300

Closed
@rochdev

Description

@rochdev

As recommended by @mcollina in nodejs/node#22360 (comment) I am opening a new issue here.

Currently, Async Hooks are implemented directly in Node. This means that newer constructs like async/await cannot be properly supported since they are language constructs interpreted directly by the underlying engine. The current workaround for that is to ask the maintainers of every module to implement AsyncResource. This model doesn't work as it cannot be expected that the authors of almost 1 million modules validate if they need to implement AsyncResource. This applies to application developers as well.

This issue impacts mostly APM vendors since we are by far the heaviest users of context propagation, but it also impacts anyone using Async Hooks to simply propagate arbitrary data across their application. For us it means we have to patch every single module we know of that should have implemented AsyncResource, and we find new ones pretty much every month. For developers who are using Async Hooks directly, it means the feature is simply broken and will randomly lose context depending on the dependencies of the project.

I unfortunately don't have enough information about how this feature evolved to propose a solution, but I think this should definitely be investigated as it means Async Hooks in their current state are basically broken and won't work in many unpredictable cases. In theory porting the feature to v8 could fix the issue, but now that Node supports different engines, this wouldn't work, meaning it should probably land as an ECMAScript standard instead.

Does anyone know what is the status of domenic/zones? Are there any alternatives in the meantime to make sure Async Hooks work natively with JavaScript constructs without the entire community having to validate their modules?

References:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions