Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context lost after await when using debugger #74

Open
nathanlepori opened this issue Aug 28, 2022 · 1 comment
Open

Context lost after await when using debugger #74

nathanlepori opened this issue Aug 28, 2022 · 1 comment

Comments

@nathanlepori
Copy link

nathanlepori commented Aug 28, 2022

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.

@nathanlepori nathanlepori changed the title Context lost f Context lost after await when using debugger Aug 28, 2022
@SiarheiBokuts
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants