-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
util: expose promise events #21857
util: expose promise events #21857
Conversation
src/async_wrap.cc
Outdated
|
||
Local<Function> fn = env->async_hooks_promise_event_function(); | ||
|
||
v8::HandleScope handle_scope(env->isolate()); |
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)
src/node.h
Outdated
@@ -612,9 +612,20 @@ NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = 0); | |||
*/ | |||
NODE_EXTERN void AtExit(Environment* env, void (*cb)(void* arg), void* arg = 0); | |||
|
|||
typedef void (*promise_hook_func) (v8::PromiseHookType type, | |||
NODE_EXTERN typedef enum { |
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
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
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.
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 |
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. |
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.
By hte way: By the same logic we should deprecate |
i can add the 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) |
i tried to design this with that in mind ( |
@benjamingr browsers provide a console warning on unhandled rejections, which they then retroactively erase if it becomes handled - node doesn't have that capability. |
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.
Again, the same argument could be made for Node.js not exiting on uncaught errors. Since a significant part of our user-base use |
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. |
the spec says aside from that, these changes also mean that in the common case, nothing is slowed down by promise state tracking. |
@devsnek I encourage you to read all the discussion above as well as the nodejs/promises repo discussions about this issue. The gist is:
In a gist the correct behaviour we settled on was:
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. |
That's not |
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) |
f83beed
to
ff94f4c
Compare
@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 |
doc/api/util.md
Outdated
* `enable` {Function} Enables the hook | ||
* `disable` {Function} Disables the hook | ||
|
||
> Stability: 1 - Experimental |
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
7ff1627
to
3dec7bb
Compare
I've signed off both PR (this and #22218), but we should really reconcile them before landing either one. See @jasnell comment #22218 (comment). |
@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? |
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! |
Adding |
@nodejs/tsc PTAL. @benjamingr your review doesn't show up anymore but i assume it is outdated. |
Like Gus said, my review is outdated.Both this and the other PR LGTM.
@devsnek This would at least need a rebase? |
that's more than I'm willing to do at this point. |
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), orvcbuild test
(Windows) passes