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

gumjs: Fix crash in Module finalizers #987

Merged
merged 2 commits into from
Jan 13, 2025
Merged

Conversation

oleavr
Copy link
Member

@oleavr oleavr commented Jan 13, 2025

Our QuickJS suspend/resume patch isn't elaborate enough to support usage from finalizers. Given that modules are created and destroyed in waves, however, it's probably a bit on the expensive side to suspend/resume JS execution during the destruction of each value. So to avoid both issues we defer the unref using an idle source.

The better longer term solution will probably be to introduce a ModuleObserver of sorts that integrates with the platform's runtime loader and manages the lifetime of each Module. This will also allow us to emit signals anytime a Module is added/removed, which is a feature that a lot of agents would benefit from.

Kudos to @mrmacete for reporting.

@oleavr oleavr requested a review from mrmacete January 13, 2025 15:40
@oleavr oleavr marked this pull request as draft January 13, 2025 15:43
@oleavr oleavr force-pushed the fix/gumjs-module-finalizers branch 3 times, most recently from c5155c7 to a4214fe Compare January 13, 2025 20:35
Our QuickJS suspend/resume patch isn't elaborate enough to support usage
from finalizers. Given that modules are created and destroyed in waves,
however, it's probably a bit on the expensive side to suspend/resume JS
execution during the destruction of each value. So to avoid both issues
we defer the unref using an idle source.

The better longer term solution will probably be to introduce a
ModuleObserver of sorts that integrates with the platform's runtime
loader and manages the lifetime of each Module. This will also allow us
to emit signals anytime a Module is added/removed, which is a feature
that a lot of agents would benefit from.

Kudos to @mrmacete for reporting.
@oleavr oleavr force-pushed the fix/gumjs-module-finalizers branch 3 times, most recently from f9e70dd to 5b8b6a5 Compare January 13, 2025 20:41
By using a single lock for all Module objects.

We should be able to revert this once we've improved our GLib static
allocation cleanup patch to use a more suitable data structure for
keeping track of mutexes.

Kudos to @mrmacete for profiling.
@oleavr oleavr force-pushed the fix/gumjs-module-finalizers branch from 5b8b6a5 to a68a566 Compare January 13, 2025 20:42
@oleavr oleavr marked this pull request as ready for review January 13, 2025 21:16
@oleavr oleavr merged commit 1267288 into main Jan 13, 2025
28 of 32 checks passed
@oleavr oleavr deleted the fix/gumjs-module-finalizers branch January 13, 2025 21:16
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.

1 participant