The async_hooks module provides an API to register callbacks tracking the lifetime of asynchronous resources created inside a Node.js application. It is currently an experimental API.
Questions tagged [async-hooks]
36 questions
1
vote
1 answer
How can I update the values of an AsyncLocalStorage?
I am using AsyncLocalStorage in a project, and I think we have a memory leak related to it.
So, my understanding from the documentation is I can start a new context using run or enterWith (I don't know the difference between them).
It is not clear…

cmaluenda
- 2,099
- 1
- 14
- 15
1
vote
1 answer
NextJS: How can I create a server side request context
I need to forward a header from the browser to an external API I call from the server side.
The external API is called from getServerSideProps and API routes.
I was thinking about implementing some sort of a request context (using AsyncLocalStorage…

buenon
- 145
- 8
1
vote
0 answers
✘ [ERROR] Could not resolve "async_hooks"
Gettiing eroor, asking to add "platform: 'node'". Can someone help me where to add it.
project is > https://github.com/dicebear/api
$wrangler dev …

Nishith P Shetty
- 23
- 5
1
vote
1 answer
How does next function work in node js async localstorage middleware
I am creating a middleware for adding trace id to each req and come across async hook and async localstorage, but I am confused about why next function is passed inside the run method, and when I remove the next function and move it outside the run…

Samuel Josh
- 17
- 3
1
vote
1 answer
Module not found: Error: Can't resolve 'async_hooks' after adding applicationinsights
Error: ./node_modules/cls-hooked/context.js
Module not found: Error: Can't resolve 'async_hooks'
After adding the applicationinsights package, I am getting the above error in my application.
I have added it by using this syntax…

Dinesh
- 411
- 6
- 19
1
vote
0 answers
Use AsyncLocalStorage to store a typeorm transaction in NestJS
I have a question regarding AsyncLocalStorage and Interceptors in NestJS.
Will there be any implications of storing a transaction (EntityManager) inside the AsyncLocalStorage? I created an interceptor to wrap my requests inside a transaction and I…

milo
- 427
- 5
- 14
1
vote
0 answers
Where can I find any docs on why Node 14 changed Promise {} into Promise {undefined, Symbol(async_id_symbol)...}?
I came across this change some time ago and I could not track it down to any release notes, neither Node or V8.
Until Node12, non-awaited promise was returning empty Promise {}, but since Node 14, it returns:
Promise {
undefined,
…

Marek Urbanowicz
- 12,659
- 16
- 62
- 87
1
vote
1 answer
AsyncLocalStorage doesn't propagate across Promise chains?
Consider the following code run under NodeJS 14.4 on Windows:
const async_hooks = require('async_hooks');
const fs = require('fs');
const util = require('util');
let asyncLocalStorage = new…

YSK
- 1,572
- 10
- 19
1
vote
0 answers
Wrong metadata when using cls-hooked
I have an app that connects to the MQTT, I want to publish 1200 devices with the id of each device as a metadata. the following is the code
"use-strict"
const RSVP = require('rsvp');
const Mqtt = require('mqtt');
const cls =…

Skander Mansouri
- 45
- 4
1
vote
1 answer
Is it possible for async_ids to overflow?
In node.js when one performs something that's async in nature, an async_id is generated for it. This id is accessible via the async_hooks API.
Since the ids are integers (64bit) is it possible that they overflow sometime?
It seems like the only…

tusharmath
- 10,622
- 12
- 56
- 83
1
vote
0 answers
Are async hooks execution IDs reassignable?
I've been wanting to maintain some data, on the basis of execution Ids and triggering async Ids provided by async_hooks. somehow I've observed that for some triggering context, let's say context "a" with execution-id 20, the context get created,…

Anupam Juniwal
- 309
- 1
- 3
- 11
0
votes
0 answers
Cannot get the correct asyncLocalStorage for a function
I have a web application with reactjs and node. Visitors can choose their language for the interface of the frontend. We use i18next to manage that in the frontend.
To sign up on the web application, a visitor needs to enter their email, we will…

SoftTimur
- 5,630
- 38
- 140
- 292
0
votes
0 answers
Issue with "AsyncLocalStorage" is not exported by "__vite-browser-external"
I'm developing an app in Nodejs and building it with vite. In my code I'm using "AsyncLocalStorage", but I get this error during build:
"AsyncLocalStorage" is not exported by "__vite-browser-external", imported by [path name].
This is my…

sara khosropour
- 11
- 3
0
votes
0 answers
Nodejs async hooks with next callback not working and crashing nodemon
Nodejs async hooks with run function having next not getting called and it crashing the nodemon
Here is my async local storage (asyncContext.ts)
import { AsyncLocalStorage } from 'async_hooks';
const asyncContext = new AsyncLocalStorage
0
votes
0 answers
AsyncResource.runInAsync argument passing RxJS
I'm having trouble figuring out how AsyncResource supports passing of arguments to the bound function.
Details
NodeJS now includes AsyncLocalStorage as an analog to a ThreadLocal in a threaded environment. That is, it provides a storage (usually a…

Jasper Blues
- 28,258
- 22
- 102
- 185