镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

AsyncLocalStore looses context in MakeCallback #43038

Description

@Flarna

Version

18.1.0, 14.19.1 (and most likely a lot others)

Platform

Tested on Microsoft Windows NT 10.0.22000.0 x64 but very likely platform independent.

Subsystem

async_hooks

What steps will reproduce the bug?

Use node::MakeCallback() with a receiver different to the AsyncResource.

See e.g. snappy 6.x which uses Nan::AsyncWorker.

In this setup the complete callback is not called with the AsyncResource as target and this results in setting the wrong object as current resource in MakeCallback.

Calling callbacks with undefined/null/global as target is not that uncommon.

The before/after callbacks are called with the correct asyncId but AsyncLocalStore relies on the current resource.

const { executionAsyncId, AsyncLocalStorage } = require("async_hooks")
const snappy = require("snappy")
const als = new AsyncLocalStorage()

als.run(15, () => {
  snappy.compress("Hello World!", () => {
    const cbId = executionAsyncId()
    console.log(`compressed: ${cbId}, als: ${als.getStore()}`)
  })
})

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

Always if MakeCallback is used with a receiver different then the AsyncResource object.

What is the expected behavior?

no context loss

What do you see instead?

context loss

Additional information

No response

Activity

  1. added
    async_hooksIssues and PRs related to the async hooks subsystem.
    on May 10, 2022
  2. Flarna commented on May 10, 2022

    @Flarna
    MemberAuthor

    fyi @nodejs/async_hooks

  3. RafaelGSS commented on May 10, 2022

    @RafaelGSS
    Member

    It's happening only in Windows?

  4. Flarna commented on May 10, 2022

    @Flarna
    MemberAuthor

    I haven't tried any other OS but I assume it's os independent. Just filled the form.

    Also node down to at least 14 is effected.

  5. github-actions commented on Jun 25, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 210 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  6. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 25, 2026
  7. github-actions commented on Jul 27, 2026

    @github-actions
    Contributor

    This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
    If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.async_local_storageIssues and PRs related to the AsyncLocalStorage API.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions