Jeff-Lewis / cls-hooked

cls-hooked : CLS using AsynWrap or async_hooks instead of async-listener for node 4.7+

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Context lost after await when using debugger

nathanlepori opened this issue · comments

See title. Execute the following repro code with and without debugger:

import {createNamespace} from 'cls-hooked';

const namespace = createNamespace('test-context');

async function fn() {
    namespace.set('test', 'test value');
    console.log('Before await: ' + namespace.get('test'));
    await Promise.resolve();
    console.log('After await: ' + namespace.get('test'));
}

namespace.run(fn);

Without debugger:

Before await: test value
After await: test value

With debugger:

Debugger listening on ws://127.0.0.1:63820/0bbb8cb0-cefc-49b4-bccf-6f16b9cc4d1c
For help, see: https://nodejs.org/en/docs/inspector                            
Debugger attached.
Before await: test value
After await: undefined                   
Waiting for the debugger to disconnect...


Tested on Node v18.7.0 and WebStorm 2022.2.1 (shouldn't make a difference but still).

My guess is that the debugger is also using async_hooks and they're somehow conflicting.

the same for me. with node.js 16 my debugger works, but with node js 18 it doesn't. it loses the context. any update on this one?