Skip to content

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-botnodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jul 29, 2020
@puzpuzpuzpuzpuzpuz added the async_hooks Issues and PRs related to the async hooks subsystem. label Jul 29, 2020
@puzpuzpuzpuzpuzpuzforce-pushed the defect/fast-promise-hook-does-not-assign-ids branch from de142ac to 61cf759CompareJuly 29, 2020 08:05
@puzpuzpuzpuzpuzpuzforce-pushed the defect/fast-promise-hook-does-not-assign-ids branch from 61cf759 to c03a3adCompareJuly 30, 2020 17:14
@puzpuzpuzpuzpuzpuzforce-pushed the defect/fast-promise-hook-does-not-assign-ids branch from c03a3ad to 2823ac3CompareJuly 31, 2020 07:54
@nodejs-github-bot
Copy link
Collaborator

@puzpuzpuz
Copy link
MemberAuthor

@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.constexprdouble 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
@puzpuzpuzpuzpuzpuzforce-pushed the defect/fast-promise-hook-does-not-assign-ids branch from 2823ac3 to f6059e3CompareJuly 31, 2020 16:49
@puzpuzpuz
Copy link
MemberAuthor

@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 <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
@puzpuzpuz
Copy link
MemberAuthor

Landed in b7a2329

@puzpuzpuzpuzpuzpuz 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 <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
@codebyterecodebytere 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 <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

async_hooksIssues and PRs related to the async hooks subsystem.author readyPRs 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

@puzpuzpuz@nodejs-github-bot@addaleax@benjamingr@Flarna@codebytere