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

[Bug] Memory Leak in getV8HeapStatistics() and getV8HeapSpaceStatistics() #387

Closed
caoccao opened this issue Aug 30, 2024 · 0 comments · Fixed by #388
Closed

[Bug] Memory Leak in getV8HeapStatistics() and getV8HeapSpaceStatistics() #387

caoccao opened this issue Aug 30, 2024 · 0 comments · Fixed by #388
Assignees
Labels
bug Something isn't working

Comments

@caoccao
Copy link
Owner

caoccao commented Aug 30, 2024

Problem

When V8 has been busy for a long while, calling getV8HeapStatistics() and getV8HeapSpaceStatistics() will experience memory leak or even crash JVM in a low chance.

Solution

Introduce sync and async modes.

Sync Mode

In sync mode, the context is purged immediately. This is the normal path without further change.

Async Mode

There are 1 global daemon thread and multiple probing threads.

Global Daemon Thread

  1. Periodically peek a priority queue for expired context.
  2. If the context is expired, request the context under the global lock.
  3. If the context exists, purge the context.
  4. If the context doesn't exist, do nothing.

Probing Thread

  1. Register the resource under the global lock.
  2. In the callback, request the context under the same global lock.
  3. If the context is purged already, return immediately.
  4. If the context is not purged, proceed to get the statistics and purge the context.
@caoccao caoccao added the bug Something isn't working label Aug 30, 2024
@caoccao caoccao self-assigned this Aug 30, 2024
caoccao added a commit that referenced this issue Aug 30, 2024
… for V8Runtime again to fix possible JVM crash
@caoccao caoccao linked a pull request Aug 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant