You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I'm using GraalVM 22.3.2 with Node.js (I'm targeting Nodejs 16.x.) installed by gu install nodejs.
It seems that AsyncLocalStorage context get lost after await statements (see the code below).
However it's available using "regular/old" Promise methods such as: .then, .finally
Also, in the example, changing .finally for try/finally make the context unavailable in the finally block.
Code:
consthttp=require("http");const{ AsyncLocalStorage }=require("async_hooks");constlogWithId=(msg)=>{const{ id }=asyncLocalStorage.getStore()||{id: "N/A"};console.log(`${msg}${id}`);};letidSeq=0;constasyncLocalStorage=newAsyncLocalStorage();constserver=http.createServer((req,res)=>{constpromise=newPromise((resolve)=>setTimeout(resolve,Math.random()*1000));asyncLocalStorage.run({id: idSeq++},()=>{logWithId("start");consthandler=async()=>{awaitpromise.then(()=>logWithId("then"));logWithId("await");// <--- Here the context gets lost};handler().finally(()=>{logWithId("finish");res.end();});});});server.listen(8080);constget=()=>newPromise((resolve)=>http.get("http://localhost:8080",null,resolve));Promise.all([get(),get(),get(),get()]).finally(()=>server.close());
Output in Node 16 (expected):
start 0
start 1
start 2
start 3
then 3
await 3
finish 3
then 2
await 2
finish 2
then 0
await 0
finish 0
then 1
await 1
finish 1
Output of $GRAALVM/bin/node 16:
start 0
start 1
start 2
start 3
then 0
await N/A
finish 0
then 3
await N/A
finish 3
then 1
await N/A
finish 1
then 2
await N/A
finish 2
This is also reproducible at least in:
graalvm 21.3.5
graalvm 22.3.3
graalvm 22.3.1
The text was updated successfully, but these errors were encountered:
PepeBotella25
changed the title
GraalVM NodeJS AsyncLocalStorage context get lost after await
GraalVM NodeJS AsyncLocalStorage context gets lost after await
Oct 3, 2023
Hi. I'm using GraalVM 22.3.2 with Node.js (I'm targeting Nodejs 16.x.) installed by
gu install nodejs
.It seems that AsyncLocalStorage context get lost after
await
statements (see the code below).However it's available using "regular/old"
Promise
methods such as:.then
,.finally
Also, in the example, changing
.finally
fortry/finally
make the context unavailable in the finally block.Code:
Output in Node 16 (expected):
Output of $GRAALVM/bin/node 16:
This is also reproducible at least in:
graalvm 21.3.5
graalvm 22.3.3
graalvm 22.3.1
The text was updated successfully, but these errors were encountered: