Skip to content
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

fix(napi): Don't run microtasks in napi_resolve_deferred #25246

Merged
merged 3 commits into from
Aug 28, 2024

Conversation

nathanwhit
Copy link
Member

Fixes an incredibly obscure bug that causes parcel's file watcher to not get any file update notifications on macOS.

The issue was that the native addon was calling napi_resolve_deferred, but when we resolved the promise, v8 was running microtasks automatically. That executed JS, which called back into the native addon and broke the addon's assumption that the call wouldn't be reentrant.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Would be lovely to have a test, but I understand it's really hard. Nice find

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

@nathanwhit nathanwhit merged commit 37501aa into denoland:main Aug 28, 2024
17 checks passed
@nathanwhit nathanwhit deleted the resolve-deferred-microtasks branch August 28, 2024 20:42
lucacasonato pushed a commit that referenced this pull request Aug 29, 2024
Fixes an incredibly obscure bug that causes parcel's file watcher to not
get any file update notifications on macOS.

The issue was that the native addon was calling `napi_resolve_deferred`,
but when we resolved the promise, v8 was running microtasks
automatically. That executed JS, which called back into the native addon
and broke the addon's assumption that the call wouldn't be reentrant.
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.

3 participants