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 OOM due to update avalanches #7

Merged
merged 2 commits into from
May 7, 2020

Conversation

RealDolos
Copy link
Contributor

Problem

  • The proxy object checks if Date.now() - proxyObject.lastUpdateCheck > updateTimer on every property access.
  • lastUpdateCheck starts out as 0 and is only updated on receiving a checking event.
  • The checking event is delayed by at least 200 ms in .checkUpdates() (running after_wait(200))
  • Therefore the above check holds true at least for the first 200ms of the process (or a little more, until the checking event is actually done emitting)
  • Therefore causing an avalanche of checkUpdates() running in "parallel", once for every property access on that proxied object while lastUpdateCheck is still 0 during those first 200ms.

Result

Process went up to consume 20GB of physical memory, swapping out most the physical memory of most other processes and eventually getting OOM killed by the kernel. Oops.

Fix

Remove the lastUpdateCheck/checkUpdates() calls from the proxy object completely. The UpdateSubscriber will perform these anyway already. No need to have this triggered on property access, kinda redundant.

Also, move out the proxyObject.subscriber setup from the proxy get into the main wrapReader body. No need to permanently check the creation when it's created exactly once anyway.

Also, triggerUpdate() is useless; stubbed.

@GitSquared
Copy link
Owner

Thanks for the PR. Will release 1.0.7 in a few minutes. 👍

@GitSquared GitSquared merged commit af2541a into GitSquared:master May 7, 2020
@RealDolos
Copy link
Contributor Author

Update tests

I knew I wanted to do something more before submitting the PR o_O

@GitSquared
Copy link
Owner

No problem, tests are a pain in the *** to update, I don't blame you 😄

GitSquared pushed a commit that referenced this pull request May 13, 2020
GitSquared pushed a commit that referenced this pull request Jan 23, 2022
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.

2 participants