GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — util: expose promise events by devsnek · Pull Request #21857 · nodejs/node

Conversation

@devsnek

@devsnek devsnek commented Jul 17, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Refs nodejs/promises-debugging#8
Closes nodejs/promises-debugging#8

exposes env promise hooks to userland

/cc @nodejs/promises-debugging @nodejs/async_hooks @BridgeAR @ljharb

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ljharb, mcollina, and benjamingr reacted with thumbs up emoji ljharb reacted with hooray emoji BridgeAR reacted with confused emoji
All reactions
  • 👍 3 reactions
  • 🎉 1 reaction
  • 😕 1 reaction
@devsnek devsnek added semver-major PRs that contain breaking changes and should be released in the next major version. async_wrap promises Issues and PRs related to ECMAScript promises. async_hooks Issues and PRs related to the async hooks subsystem. labels Jul 17, 2018
@nodejs-github-bot

nodejs-github-bot commented Jul 17, 2018

Copy link
Copy Markdown
Collaborator

@devsnek build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/296/pipeline

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs involving general changes in the lib/ or src/ directories. label Jul 17, 2018
@devsnek devsnek added wip Issues and PRs that are still a work in progress. and removed lib / src Issues and PRs involving general changes in the lib/ or src/ directories. labels Jul 17, 2018
addaleax
addaleax reviewed Jul 17, 2018
View reviewed changes
Comment thread src/async_wrap.cc Outdated

@addaleax addaleax Jul 17, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This would technically need to be swapped with the line above (it’s only working because we’re doing an evil hack and look into V8’s object representations to load persistent references faster)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node.h Outdated

@addaleax addaleax Jul 17, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I don’t think it really makes sense to add NODE_EXTERN to a type definition; also, the typedef is redundant, just using enum PromiseHookType { … }; should work the same way

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@devsnek devsnek Jul 17, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

this doesn't compile without the typedef

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AndreasMadsen
AndreasMadsen self-requested a review July 17, 2018 19:25
benjamingr
benjamingr previously requested changes Jul 17, 2018
View reviewed changes

@benjamingr benjamingr left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is backwards incompatible and will break code for a worse off default.

This also goes against the ongoing work we've been doing at @nodejs/promises-debugging and the work.

I am strictly -1 on this change before the survey we've been working on with the foundation is sent out and we've gathered sufficient data.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@benjamingr

benjamingr commented Jul 17, 2018

Copy link
Copy Markdown
Member

This allows the default behaviour in node to follow the intention of js

This is also not true and was not the intention - browsers error on unhandled rejections too. One of the things we've been getting since adding the unhandledRejection hook is constant positive feedback for logging as well as negative one for not crashing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Jul 17, 2018

Copy link
Copy Markdown
Member

It would have been great to discuss things like that in the promises working group. Since this is completely backwards incompatible I am strongly -1. It is not an option to remove the regular way how people deal with this.

AFAIK it is also not possible to mirror the current implementation in userland even with the events exposed.

I believe it is best to keep these things in core so everyone takes advantage of it by default. Opt-out instead of opt-in.

benjamingr reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell
jasnell requested a review from BridgeAR July 17, 2018 19:49
BridgeAR
BridgeAR previously requested changes Jul 17, 2018
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

-1 due to the mentioned reasons.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@benjamingr

benjamingr commented Jul 17, 2018

Copy link
Copy Markdown
Member

By hte way: By the same logic we should deprecate uncaughtException, stop exiting or logging on errors and expose an async_hook for exiting.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Jul 17, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

i can add the promiseResolve back as deprecated if you want? i assumed it wasn't needed because async_hooks is experimental still...

as to the argument about how promises are supposed to work: they are explicitly intended to be able to silently fail. what browser consoles do is completely irrelevant because that's a debug facility. (we could probably do the same thing with our inspector, which would be also fine)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Jul 17, 2018

Copy link
Copy Markdown
Member Author

@BridgeAR

AFAIK it is also not possible to mirror the current implementation in userland even with the events exposed.

i tried to design this with that in mind (rejectWithNoHandler includes the rejection reason, etc) and using process.nextTick will make it identical (except for storing asyncId instead of promise)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ljharb

ljharb commented Jul 17, 2018

Copy link
Copy Markdown
Member

@benjamingr browsers provide a console warning on unhandled rejections, which they then retroactively erase if it becomes handled - node doesn't have that capability.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@benjamingr

benjamingr commented Jul 17, 2018

Copy link
Copy Markdown
Member

they are explicitly intended to be able to silently fail.

I do not believe this is the case nor does the spec make any such requirement. That said: Under all proposed implementations promises are able to silently fail - just like you can ignore synchronous errors:

process.on('uncaughtException', e => { /* console.log('https://i.imgur.com/c4jt321.png') */ });

You can ignore unhandled rejections:

process.on('uncaughtException', e => { /* console.log('https://i.imgur.com/c4jt321.png') */ });

Which will continue to work forever under all proposed changes. The question is about what the default behaviour should be.

We have a consensus at this point in Node.js that ignoring uncaught errors should not be the default behaviour.

what browser consoles do is completely irrelevant because that's a debug facility. this is all for debugging

Again, the same argument could be made for Node.js not exiting on uncaught errors. Since a significant part of our user-base use async/await it means that in practice they don't distinguish between unhandled rejections and uncaught errors in terms of how they handle errors anyway.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@benjamingr

benjamingr commented Jul 17, 2018

Copy link
Copy Markdown
Member

@ljharb

@benjamingr browsers provide a console warning on unhandled rejections, which they then retroactively erase if it becomes handled - node doesn't have that capability.

The browser error handling model is completely different though - Node.js crashes on uncaught errors (by default) whereas browsers "chug on". Both behaviours have been this way for well over 8 years.

I was just pointing out browsers consider unhandled rejections as an error and log based on it. Node.js provides the "erasing" by providing the "rejectionHandled" hook which I haven't actually seen ever used but it's possible and was added in the same PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Jul 17, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I do not believe this is the case nor does the spec make any such requirement.

the spec says An implementation of HostPromiseRejectionTracker must complete normally in all cases.. i would argue that killing the process is not a normal completion, but i don't really want to get into those semantics.

aside from that, unhandledRejection (with the emit on gc proposal) can't guarantee that it will be fired for the things it should be unless someone is using global.gc, which kind of undermines the debugging potential of it. By not making these (arguably confusing for that reason) apis, we can let people find the best behaviour for what they're trying to do, similar to how people often use tools like winston even though node has console.

these changes also mean that in the common case, nothing is slowed down by promise state tracking.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@benjamingr

benjamingr commented Jul 17, 2018

Copy link
Copy Markdown
Member

@devsnek I encourage you to read all the discussion above as well as the nodejs/promises repo discussions about this issue.

The gist is:

  • We can't really know when a promise rejection will never be handled (halting problem)
  • We can warn when a promise is handled asynchronously (and not within a microtask) since that has been very rare in practice. We've added this and got tremendous positive community feedback.
  • GC is the only tool we have for detecting most true positives but no false positives at all. Note this has false negatives like a unhandled rejection the app keeps a global reference for. Also note this cannot be implemented in user-land since it relies on core GC behaviour.
  • Since GC isn't perfect - when a promise isn't handled synchronously there is a high true positive chance - so it makes sense to still log these.
  • We let users choose the behaviour they want in all cases. This is only about the default behaviour.

In a gist the correct behaviour we settled on was:

  • If you can prove (GC) an exception is unhandled do the same thing we do for uncaught exceptions - exit the process.
  • If you think with a high probability that a rejection is unhandled - show that as a warning since that's what most users find beneficial (we have a recent Netflix survey that also shows this). This is easy to opt out of.

It's not perfect - but sadly I think it's the best we might be able to do. You are encouraged to read the background discussions and participate in the promises-debugging team which still has an open "call for members". We'd love for more people to get involved.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@benjamingr

benjamingr commented Jul 17, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

the spec says An implementation of HostPromiseRejectionTracker must complete normally in all cases.. i would argue that killing the process is not a normal completion, but i don't really want to get into those semantics.

That's not HostPromiseRejectionTracker (which just tracks any rejections) - we are strictly talking about code that happens after that when the promise gets GCd. At this point control has been yielded to the platform and only platform code is running. An implementation may do as it pleases. This is entirely Node.js's domain and not ECMAScript's.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Jul 17, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Also note this cannot be implemented in user-land since it relies on core GC behaviour.

the destroy hook lets us do that right?

in any case, wasn't the whole point here to catch all the bad things happening? if we don't catch them we aren't solving the problem (with regard to gc) and having that as a default is imo confusing and misleading (not to mention that having all these promise state trackers by default is annoying)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek
devsnek force-pushed the feature/async_hooks-promise-event branch 2 times, most recently from f83beed to ff94f4c Compare July 17, 2018 22:39
@devsnek devsnek removed the semver-major PRs that contain breaking changes and should be released in the next major version. label Jul 17, 2018
@devsnek

devsnek commented Jul 17, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@benjamingr @BridgeAR unhandledRejection event remains. This PR still provides a solution to exposing the events requested in nodejs/promises-debugging#8 (and other fun stuff)

i still strongly recommend against node defining what an unhandled rejection is in any case but that's a conversation for another issue/pr

benjamingr reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek devsnek removed the wip Issues and PRs that are still a work in progress. label Jul 17, 2018
jasnell
jasnell reviewed Aug 9, 2018
View reviewed changes
Comment thread doc/api/util.md Outdated

@jasnell jasnell Aug 9, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

nit: This should likely be moved above the arguments list

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jasnell
jasnell approved these changes Aug 9, 2018
View reviewed changes
@devsnek
util: expose promise events
3dec7bb
@devsnek
devsnek force-pushed the feature/async_hooks-promise-event branch from 7ff1627 to 3dec7bb Compare August 9, 2018 23:25
@devsnek

devsnek commented Aug 9, 2018

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mcollina

mcollina commented Aug 10, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I've signed off both PR (this and #22218), but we should really reconcile them before landing either one. See @jasnell comment #22218 (comment).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung mentioned this pull request Aug 10, 2018
Investigate flaky test-module-loading-globalpaths with --worker on #22228
Closed
@BridgeAR BridgeAR added the tsc-agenda Issues and PRs to discuss during Technical Steering Committee meetings. label Aug 10, 2018
@mhdawson mhdawson mentioned this pull request Aug 13, 2018
Node.js Foundation Technical Steering Committee (TSC) Meeting 2018-08-15 nodejs/TSC#585
Closed
@Trott

Trott commented Aug 13, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@BridgeAR Same question as in the other PR: Can you explain what you'd like the TSC to decide or do with this at the meeting? (Or should we remove it from the agenda?)

EDIT: Are you asking the TSC to decide whether we should go with this approach or #22218? Is it unlikely that you and @devsnek or others will come to an agreement on that?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhdawson mhdawson mentioned this pull request Aug 20, 2018
Node.js Foundation Technical Steering Committee (TSC) Meeting 2018-08-22 nodejs/TSC#587
Closed
@Trott

Trott commented Aug 25, 2018

Copy link
Copy Markdown
Member

If I've understood the conversation above, there are currently 3 objecting Collaborators on this PR: @benjamingr, @BridgeAR, and @AndreasMadsen. If I've misunderstood and any of you don't object to this at this time, please comment! Thanks!

AndreasMadsen reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott Trott added the blocked PRs that are blocked by other issues or PRs. label Aug 25, 2018
@Trott

Trott commented Aug 25, 2018

Copy link
Copy Markdown
Member

Adding blocked here and in #22218 pending decision about which approach to go with.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhdawson mhdawson mentioned this pull request Aug 27, 2018
Node.js Foundation Technical Steering Committee (TSC) Meeting 2018-08-29 nodejs/TSC#590
Closed
cjihrig
cjihrig approved these changes Aug 29, 2018
View reviewed changes
@devsnek

devsnek commented Aug 29, 2018

Copy link
Copy Markdown
Member Author

@nodejs/tsc PTAL.

@benjamingr your review doesn't show up anymore but i assume it is outdated.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@benjamingr
benjamingr dismissed their stale review August 29, 2018 13:10

Like Gus said, my review is outdated.Both this and the other PR LGTM.

@fhinkel

fhinkel commented Aug 29, 2018

Copy link
Copy Markdown
Contributor

Thanks everybody for putting so much work into this! Would somebody be willing to summarize #22218 and #21857 so it's easier to understand the pros and cons of the two approaches?

TimothyGu reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott Trott removed the tsc-agenda Issues and PRs to discuss during Technical Steering Committee meetings. label Aug 29, 2018
@Trott Trott mentioned this pull request Aug 29, 2018
opt-out or opt-in for warnings etc. #22587
Closed
@devsnek
devsnek requested a review from a team September 5, 2018 01:40
@devsnek devsnek added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 5, 2018
@Trott
Trott removed the request for review from a team September 8, 2018 01:48
@jasnell jasnell mentioned this pull request Sep 12, 2018
[Discuss] Resolving the unhandled rejections issue #22822
Closed
@addaleax addaleax removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 17, 2018
@addaleax

addaleax commented Sep 17, 2018

Copy link
Copy Markdown
Member

@devsnek This would at least need a rebase?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Sep 17, 2018

Copy link
Copy Markdown
Member Author

that's more than I'm willing to do at this point.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek devsnek closed this Sep 17, 2018
@devsnek
devsnek deleted the feature/async_hooks-promise-event branch September 17, 2018 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@addaleax addaleax addaleax left review comments
@mcollina mcollina mcollina approved these changes
@jasnell jasnell jasnell approved these changes
@cjihrig cjihrig cjihrig approved these changes
@benjamingr benjamingr benjamingr left review comments
@AndreasMadsen AndreasMadsen Awaiting requested review from AndreasMadsen
@BridgeAR BridgeAR Awaiting requested review from BridgeAR
+2 more reviewers
@ofrobots ofrobots ofrobots left review comments
@targos targos targos left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

blocked PRs that are blocked by other issues or PRs. promises Issues and PRs related to ECMAScript promises. semver-minor PRs that contain new features and should be released in the next minor version. util Issues and PRs related to the built-in util module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

16 participants

@devsnek @nodejs-github-bot @benjamingr @BridgeAR @ljharb @AndreasMadsen @mcollina @mike-kaufman @addaleax @Trott @fhinkel @ofrobots @jasnell @targos @cjihrig @TimothyGu
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.