Skip to content

Fix reporting handled promises as unhandled in tracker #1038

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

Merged
merged 1 commit into from
May 1, 2025

Conversation

saghul
Copy link
Contributor

@saghul saghul commented Apr 28, 2025

Enqueue a job which will perform the check after all reactions. Also drop the case in which the tracker gets called with true, the handler now only gets called when the promise rejection is unhandled.

Fixes: #39

quickjs.h Outdated
@@ -1020,10 +1020,9 @@ typedef void JSPromiseHook(JSContext *ctx, JSPromiseHookType type,
JS_EXTERN void JS_SetPromiseHook(JSRuntime *rt, JSPromiseHook promise_hook,
void *opaque);

/* is_handled = true means that the rejection is handled */
/* only gets called on unhandled rejections. */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bnoordhuis LMK what you think about this change. I can drop the 2nd commit and leave it more backwards compatible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Without is_handled, you can't implement async_hooks, so either it needs to be restored or there should be a promise hook for rejected promises.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, I'll rework it.

Choose a reason for hiding this comment

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

Without is_handled, you can't implement async_hooks, so either it needs to be restored or there should be a promise hook for rejected promises.

It would be great if the new Promise Hook API could also pick up rejections. :)
It is a bit complicated that the methods for detecting asynchronous events are divided into the PromiseHook API, Promise Rejection Tracker, and FinalizationRegistry, so I think it would be a good idea to integrate the Promise Rejection Tracker into the PromiseHook API. However, I don't know the history of the Promise Rejection Tracker, so if you can't integrate it, that's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose I could add a new hook JS_PROMISE_HOOK_REJECT and then an extra API JS_PromiseIsHandled and we could drop this altogether.

Thoughts @bnoordhuis ?

quickjs.h Outdated
@@ -1020,10 +1020,9 @@ typedef void JSPromiseHook(JSContext *ctx, JSPromiseHookType type,
JS_EXTERN void JS_SetPromiseHook(JSRuntime *rt, JSPromiseHook promise_hook,
void *opaque);

/* is_handled = true means that the rejection is handled */
/* only gets called on unhandled rejections. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Without is_handled, you can't implement async_hooks, so either it needs to be restored or there should be a promise hook for rejected promises.

@saghul saghul force-pushed the fix-unhandled-rejection-tracker branch 2 times, most recently from 77bb476 to 0ee636b Compare April 30, 2025 10:56
Enqueue a job which will perform the check after all reactions.

Fixes: #39
@saghul saghul force-pushed the fix-unhandled-rejection-tracker branch from 0ee636b to 2358d21 Compare April 30, 2025 11:05
@saghul
Copy link
Contributor Author

saghul commented Apr 30, 2025

@bnoordhuis Updated, PTAL!

@saghul saghul merged commit a75498b into master May 1, 2025
127 checks passed
@saghul saghul deleted the fix-unhandled-rejection-tracker branch May 1, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhandled promise tracker called incorrectly
3 participants