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

async_hooks: fix id assignment in fast-path promise hook #34548

Conversation

puzpuzpuz
Copy link
Member

This PR fixes a bug introduced by #34512.

Native side of fast-path promise hook was not calling JS fastPromiseHook function when there were no async ids previously assigned to the promise. Because of that already created promises could not get id assigned in situations when an async hook without a before listener function is enabled after their creation. As the result executionAsyncId could return wrong id when called within promise's .then().

Refs: #34512

cc @nodejs/async_hooks

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jul 29, 2020
@puzpuzpuz puzpuzpuz added the async_hooks Issues and PRs related to the async hooks subsystem. label Jul 29, 2020
@puzpuzpuz puzpuzpuz force-pushed the defect/fast-promise-hook-does-not-assign-ids branch from de142ac to 61cf759 Compare July 29, 2020 08:05
src/async_wrap.cc Show resolved Hide resolved
@puzpuzpuz puzpuzpuz force-pushed the defect/fast-promise-hook-does-not-assign-ids branch from 61cf759 to c03a3ad Compare July 30, 2020 17:14
src/async_wrap.cc Outdated Show resolved Hide resolved
@puzpuzpuz puzpuzpuz force-pushed the defect/fast-promise-hook-does-not-assign-ids branch from c03a3ad to 2823ac3 Compare July 31, 2020 07:54
@nodejs-github-bot
Copy link
Collaborator

@puzpuzpuz
Copy link
Member Author

@addaleax thanks for the helpful review!

@addaleax
Copy link
Member

Looks like the debug build breaks here with a linking error – you may want to add something like

// TODO(addaleax): Remove once we're on C++17.
constexpr double AsyncWrap::kInvalidAsyncId;

somewhere (this is a common issue with C++14, you can search the codebase for more instances of the TODO message to see workarounds for similar problems with static constexpr class members).

Native side of fast-path promise hook was not calling JS fastPromiseHook
function when there were no async ids previously assigned to the promise.
Because of that already created promises could not get id assigned in
situations when an async hook without a before listener function is enabled
after their creation. As the result executionAsyncId could return wrong id
when called within promise's .then().

Refs: nodejs#34512
@puzpuzpuz puzpuzpuz force-pushed the defect/fast-promise-hook-does-not-assign-ids branch from 2823ac3 to f6059e3 Compare July 31, 2020 16:49
@puzpuzpuz
Copy link
Member Author

@addaleax thanks for sharing this workaround. I've added the duplicate constexpr with the same TODO (hope you don't mind that it mentions you).

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/32592/

puzpuzpuz added a commit that referenced this pull request Aug 3, 2020
Native side of fast-path promise hook was not calling JS
fastPromiseHook function when there were no async ids
previously assigned to the promise. Because of that already
created promises could not get id assigned in situations
when an async hook without a before listener function is
enabled after their creation. As the result executionAsyncId
could return wrong id when called within promise's .then().

Refs: #34512

PR-URL: #34548
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
@puzpuzpuz
Copy link
Member Author

Landed in b7a2329

@puzpuzpuz puzpuzpuz closed this Aug 3, 2020
@puzpuzpuz puzpuzpuz deleted the defect/fast-promise-hook-does-not-assign-ids branch August 3, 2020 07:37
codebytere pushed a commit that referenced this pull request Aug 6, 2020
Native side of fast-path promise hook was not calling JS
fastPromiseHook function when there were no async ids
previously assigned to the promise. Because of that already
created promises could not get id assigned in situations
when an async hook without a before listener function is
enabled after their creation. As the result executionAsyncId
could return wrong id when called within promise's .then().

Refs: #34512

PR-URL: #34548
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
@codebytere codebytere mentioned this pull request Aug 10, 2020
codebytere pushed a commit that referenced this pull request Aug 11, 2020
Native side of fast-path promise hook was not calling JS
fastPromiseHook function when there were no async ids
previously assigned to the promise. Because of that already
created promises could not get id assigned in situations
when an async hook without a before listener function is
enabled after their creation. As the result executionAsyncId
could return wrong id when called within promise's .then().

Refs: #34512

PR-URL: #34548
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants