Skip to content

Context lost after await when using debugger #74

@nathanlepori

Description

@nathanlepori

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions