Skip to content

process: refactor promise rejection handling - #25200

Closed
joyeecheung wants to merge 4 commits into
nodejs:masterfrom
joyeecheung:refactor-tasks
Closed

process: refactor promise rejection handling#25200
joyeecheung wants to merge 4 commits into
nodejs:masterfrom
joyeecheung:refactor-tasks

Conversation

@joyeecheung

@joyeecheungjoyeecheung commented Dec 24, 2018

Copy link
Copy Markdown
Member

It's easier to review without the indentation changes: https://github.com/nodejs/node/pull/25200/files?w=1

src: refactor tickInfo access

  • Wrap access to tickInfo fields in functions
  • Rename kHasScheduled to kHasTickScheduled and
    kHasPromiseRejections to kHasRejectionToWarn for clarity - note
    the latter will be set to false if the rejection does not lead to
    a warning so the previous description is not accurate.
  • Set kHasRejectionToWarn in JS land of relying on C++ to use
    an implict contract (return value of the promise rejection handler)
    to set it, as the decision is made entirely in JS land.
  • Destructure promise reject event constants.

process: make tick callback and promise rejection callback more robust

  • Rename internalTickCallback to processTicksAndRejections, make
    sure it does not get called if it's not set in C++.
  • Rename emitPromiseRejectionWarnings to processPromiseRejections
    since it also emit events that are not warnings.
  • Sets SetPromiseRejectCallback in the Environment constructor
    to make sure it only gets called once per-isolate, and make
    sure it does not get called if it's not set in C++.
  • Wrap promise rejection callback initialization into
    listenForRejections().
  • Add comments.
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Dec 24, 2018
@joyeecheung

joyeecheung commented Dec 24, 2018

Copy link
Copy Markdown
MemberAuthor

@starkwangstarkwang added the promises Issues and PRs related to ECMAScript promises. label Dec 24, 2018
Comment threadlib/internal/process/promises.js Outdated
Comment threadlib/internal/process/next_tick.js Outdated
Comment threadlib/internal/process/promises.js Outdated
@joyeecheung

Copy link
Copy Markdown
MemberAuthor

I left the more opinionated refactoring out of this PR and focused on renaming & improving robustness.

CI: https://ci.nodejs.org/job/node-test-pull-request/19808/
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/284/

@Trott

Copy link
Copy Markdown
Member

Comment threadsrc/env.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you leave a TODO comment for me? We’re letting a single Environment take control of per-Isolate state here – I know it’s been that way before, but it’s not what we should be doing…

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity - when would multiple Environments correspond to an isolate?

@Trott

Copy link
Copy Markdown
Member

@Trott

Copy link
Copy Markdown
Member

Getting closer...

Resume Build CI: https://ci.nodejs.org/job/node-test-pull-request/19825/

Comment threadlib/internal/process/promises.js Outdated
Comment threadlib/internal/process/promises.js Outdated
Comment threadlib/internal/process/promises.js Outdated
- Wrap access to tickInfo fields in functions
- Rename `kHasScheduled` to `kHasTickScheduled` and
`kHasPromiseRejections` to `kHasRejectionToWarn` for clarity - note
the latter will be set to false if the rejection does not lead to
a warning so the previous description is not accurate.
- Set `kHasRejectionToWarn` in JS land of relying on C++ to use
an implict contract (return value of the promise rejection handler)
to set it, as the decision is made entirely in JS land.
- Destructure promise reject event constants.
- Rename `internalTickCallback` to `processTicksAndRejections`, make
sure it does not get called if it's not set in C++.
- Rename `emitPromiseRejectionWarnings` to `processPromiseRejections`
since it also emit events that are not warnings.
- Sets `SetPromiseRejectCallback` in the `Environment` constructor
to make sure it only gets called once per-isolate, and make
sure it does not get called if it's not set in C++.
- Wrap promise rejection callback initialization into
`listenForRejections()`.
- Add comments.
@joyeecheung

Copy link
Copy Markdown
MemberAuthor

Addressed the reviews. CI: https://ci.nodejs.org/job/node-test-pull-request/19937/

@joyeecheungjoyeecheung added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 4, 2019
@joyeecheung

Copy link
Copy Markdown
MemberAuthor

Landed in f6a1d88...d18b0a0, thanks!

@joyeecheungjoyeecheung removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 6, 2019
joyeecheung added a commit that referenced this pull request Jan 6, 2019
- Wrap access to tickInfo fields in functions
- Rename `kHasScheduled` to `kHasTickScheduled` and
`kHasPromiseRejections` to `kHasRejectionToWarn` for clarity - note
the latter will be set to false if the rejection does not lead to
a warning so the previous description is not accurate.
- Set `kHasRejectionToWarn` in JS land of relying on C++ to use
an implict contract (return value of the promise rejection handler)
to set it, as the decision is made entirely in JS land.
- Destructure promise reject event constants.
PR-URL: #25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
joyeecheung added a commit that referenced this pull request Jan 6, 2019
- Rename `internalTickCallback` to `processTicksAndRejections`, make
sure it does not get called if it's not set in C++.
- Rename `emitPromiseRejectionWarnings` to `processPromiseRejections`
since it also emit events that are not warnings.
- Sets `SetPromiseRejectCallback` in the `Environment` constructor
to make sure it only gets called once per-isolate, and make
sure it does not get called if it's not set in C++.
- Wrap promise rejection callback initialization into
`listenForRejections()`.
- Add comments.
PR-URL: #25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@addaleax

Copy link
Copy Markdown
Member

This needs to be backported to v11.x.

refack pushed a commit to refack/node that referenced this pull request Jan 14, 2019
- Wrap access to tickInfo fields in functions
- Rename `kHasScheduled` to `kHasTickScheduled` and
`kHasPromiseRejections` to `kHasRejectionToWarn` for clarity - note
the latter will be set to false if the rejection does not lead to
a warning so the previous description is not accurate.
- Set `kHasRejectionToWarn` in JS land of relying on C++ to use
an implict contract (return value of the promise rejection handler)
to set it, as the decision is made entirely in JS land.
- Destructure promise reject event constants.
PR-URL: nodejs#25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
refack pushed a commit to refack/node that referenced this pull request Jan 14, 2019
- Rename `internalTickCallback` to `processTicksAndRejections`, make
sure it does not get called if it's not set in C++.
- Rename `emitPromiseRejectionWarnings` to `processPromiseRejections`
since it also emit events that are not warnings.
- Sets `SetPromiseRejectCallback` in the `Environment` constructor
to make sure it only gets called once per-isolate, and make
sure it does not get called if it's not set in C++.
- Wrap promise rejection callback initialization into
`listenForRejections()`.
- Add comments.
PR-URL: nodejs#25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@addaleax

Copy link
Copy Markdown
Member

This applies cleanly now. :)

addaleax pushed a commit that referenced this pull request Jan 15, 2019
- Wrap access to tickInfo fields in functions
- Rename `kHasScheduled` to `kHasTickScheduled` and
`kHasPromiseRejections` to `kHasRejectionToWarn` for clarity - note
the latter will be set to false if the rejection does not lead to
a warning so the previous description is not accurate.
- Set `kHasRejectionToWarn` in JS land of relying on C++ to use
an implict contract (return value of the promise rejection handler)
to set it, as the decision is made entirely in JS land.
- Destructure promise reject event constants.
PR-URL: #25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax pushed a commit that referenced this pull request Jan 15, 2019
- Rename `internalTickCallback` to `processTicksAndRejections`, make
sure it does not get called if it's not set in C++.
- Rename `emitPromiseRejectionWarnings` to `processPromiseRejections`
since it also emit events that are not warnings.
- Sets `SetPromiseRejectCallback` in the `Environment` constructor
to make sure it only gets called once per-isolate, and make
sure it does not get called if it's not set in C++.
- Wrap promise rejection callback initialization into
`listenForRejections()`.
- Add comments.
PR-URL: #25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@BridgeARBridgeAR mentioned this pull request Jan 16, 2019
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Jan 16, 2019
- Wrap access to tickInfo fields in functions
- Rename `kHasScheduled` to `kHasTickScheduled` and
`kHasPromiseRejections` to `kHasRejectionToWarn` for clarity - note
the latter will be set to false if the rejection does not lead to
a warning so the previous description is not accurate.
- Set `kHasRejectionToWarn` in JS land of relying on C++ to use
an implict contract (return value of the promise rejection handler)
to set it, as the decision is made entirely in JS land.
- Destructure promise reject event constants.
PR-URL: nodejs#25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Jan 16, 2019
- Rename `internalTickCallback` to `processTicksAndRejections`, make
sure it does not get called if it's not set in C++.
- Rename `emitPromiseRejectionWarnings` to `processPromiseRejections`
since it also emit events that are not warnings.
- Sets `SetPromiseRejectCallback` in the `Environment` constructor
to make sure it only gets called once per-isolate, and make
sure it does not get called if it's not set in C++.
- Wrap promise rejection callback initialization into
`listenForRejections()`.
- Add comments.
PR-URL: nodejs#25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Jan 17, 2019
- Wrap access to tickInfo fields in functions
- Rename `kHasScheduled` to `kHasTickScheduled` and
`kHasPromiseRejections` to `kHasRejectionToWarn` for clarity - note
the latter will be set to false if the rejection does not lead to
a warning so the previous description is not accurate.
- Set `kHasRejectionToWarn` in JS land of relying on C++ to use
an implict contract (return value of the promise rejection handler)
to set it, as the decision is made entirely in JS land.
- Destructure promise reject event constants.
PR-URL: nodejs#25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Jan 17, 2019
- Rename `internalTickCallback` to `processTicksAndRejections`, make
sure it does not get called if it's not set in C++.
- Rename `emitPromiseRejectionWarnings` to `processPromiseRejections`
since it also emit events that are not warnings.
- Sets `SetPromiseRejectCallback` in the `Environment` constructor
to make sure it only gets called once per-isolate, and make
sure it does not get called if it's not set in C++.
- Wrap promise rejection callback initialization into
`listenForRejections()`.
- Add comments.
PR-URL: nodejs#25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorinsMylesBorins mentioned this pull request Jan 24, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.lib / srcIssues and PRs related to general changes in the lib or src directory.promisesIssues and PRs related to ECMAScript promises.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@joyeecheung@nodejs-github-bot@Trott@addaleax@jasnell@BridgeAR@targos@starkwang