Skip to content

AsyncLocalStorage.disable() strange behaviour #48480

Closed
@regevbr

Description

@regevbr

Version

v18.12.1

Platform

Linux machine 5.15.0-73-generic #80-Ubuntu SMP Mon May 15 15:18:26 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

const { AsyncLocalStorage } = require('async_hooks');
const assert = require('assert');

const als = new AsyncLocalStorage();
assert(als.getStore() === undefined);
als.enterWith({ foo: 'bar' });
assert(als.getStore()?.foo === 'bar');
als.disable();
assert(als.getStore() === undefined);
als.run({ foo: 'zoo' }, () => {
        assert(als.getStore()?.foo === 'zoo');
});
assert(als.getStore() === undefined);

How often does it reproduce? Is there a required condition?

reproduces every time

What is the expected behavior? Why is that the expected behavior?

According to the docs

When calling asyncLocalStorage.disable(), all current contexts linked to the instance will be exited.

I would expect that contexts will be exited

What do you see instead?

if you keep using the storage after disable, the context is restored

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions