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

Potential memory leak when user worker terminates #133

Open
janpaul123 opened this issue Mar 10, 2022 · 0 comments
Open

Potential memory leak when user worker terminates #133

janpaul123 opened this issue Mar 10, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@janpaul123
Copy link
Contributor

We rely on the FinalizationRegistry notifying us when ZapBuffers get garbage collected. However, these never get called when you terminate a worker, which means that in such a case we never deallocate those buffers.

See this article:

it's safe to assume that engines will garbage collect, and finalization callbacks will be called at some later time, unless the environment is discarded (such as the tab closing, or the worker terminating). Keep this uncertainty in mind when writing code.

There are two ways in which a Worker can be terminated:

  1. The close function within the Worker itself. We can monkey-patch it to do our deallocations when it is called; that's easy enough.
  2. The terminate function outside of the Worker. This is trickier.
  • We could discourage people from using it (and instead using close) by having a regular "keep alive" poll to our Workers (or just in development builds), and throwing an error or warning if a Worker disappeared.
  • We could also be more sophisticated and keeping track of resources in each Worker so we can deallocate them when they disappear.
  • However, these keep alive signals wouldn't work in cases where a Worker is synchronously blocked for a while — in that case there is no way to differentiate between long blocking versus being terminated, unless we deliberately unblock the Worker once in a while (e.g. by writing this in a custom stdlib Custom Rust stdlib #66).
  • We could also monkey-patch terminate by having it throw an error, but people can override that or not load our library in the environment from which they call `terminate.
  1. Silent termination of Workers by a browser. This is less common but it can happen.
@janpaul123 janpaul123 added the bug Something isn't working label Mar 10, 2022
@janpaul123 janpaul123 added this to the Basic stabilization milestone Mar 10, 2022
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
Status: Backlog
Development

No branches or pull requests

1 participant