Repository navigation
Conversation
…ion builds VM#execute and UpdatingVM#execute reset @glimmer/validator's tracking state when a render throws, so an opcode that opened a tracking frame and never reached its matching close does not leave the frame open. That cleanup only ran in DEBUG builds: the production branch was a bare call to _execute. In a browser the difference never shows, since the page is already broken. In a long-lived server-side renderer (FastBoot) the process keeps going with CURRENT_TRACKER still set, and every subsequent render adds its tags to that orphaned tracker's Set. That is a memory leak that grows until the worker runs out of heap. In one production deployment it reproduced as a worker crash every 3-5 hours for as long as logs existed, armed by a single SSR render error. The reset now runs in every build; only the diagnostic console.error stays behind DEBUG. Tests cover a throwing component constructor and a throwing rerender, through both the DOM and the server-side (simple-dom) delegates. They pass on development builds either way and failed on production builds before this change. Fixes emberjs#20130
NullVoxPopuli
left a comment
There was a problem hiding this comment.
Can you run pnpm dlx [email protected] on the comment blocks?
Also, just trying to think about how to improve your app's liklihood for success when deployed -- do you have tests for all the pages you want to render in ssr?
This is one of those things where, while I agree a memory leak is bad), your page is just already broken, and that is what needs fixing -- but I suspect that perhaps it could be caught in dev during testing?
| // only the diagnostic report is DEBUG-only. | ||
| let message = resetTracking(); | ||
|
|
||
| if (DEBUG) { |
There was a problem hiding this comment.
if we're going to bring an error-recovery feature out of debug mode, and in to production, we should keep the logged message.
There was a problem hiding this comment.
Thanks for the review NullVox!
I've moved the log outside of the debug line, and passed a message through from the resetTracking function so that it doesn't say 'Error occurred undefined'.
You're right that the primary issue is in my app (and its lack of test coverage for SSR). I'll fix that on my side and it's reasonable to expect anyone else running into this problem to do the same, so i'm easy whether you want to merge or close this PR. (also obvs let me know if you need me to make any other changes)
Thank you for your work
There was a problem hiding this comment.
No worries, i think the primary bug you're fixing here is a lack of error. If you had an error reported, you wound have more easily known something was wrong!
So, this pr is still valuable!
|
(also) thanks for submitting a change to improve memory efficiency! |
Shorter sentences, breaks at pauses, and varied rhythm, as checked by nollm 0.7.0 on the lines this branch touches.
The reset already ran in every build; the console.error that reports it was still DEBUG-only. resetTracking() returns a short message outside DEBUG so the report does not print undefined there.
| /// EXECUTION | ||
|
|
||
| execute(initialize?: (vm: this) => void): RenderResult { | ||
| if (DEBUG) { |
There was a problem hiding this comment.
so, I think my main concern here is that with this unwrapped from DEBUG, the only path through the VM has extra alocations, and then still doesn't throw an error (making the core problem harder to find).
I wonder if there is there a way error in a more central location so we also don't have pay for extra variable/block/scope allocations in production?
VM#execute and UpdatingVM#execute reset @glimmer/validator's tracking state when a render throws, so an opcode that opened a tracking frame and never reached its matching close does not leave the frame open. That cleanup only ran in DEBUG builds: the production branch was a bare call to _execute.
In a browser the difference never shows, since the page is already broken. In a long-lived server-side renderer (FastBoot) the process keeps going with CURRENT_TRACKER still set, and every subsequent render adds its tags to that orphaned tracker's Set. That is a memory leak that grows until the worker runs out of heap. In one production deployment it reproduced as a worker crash every 3-5 hours for as long as logs existed, armed by a single SSR render error.
The reset now runs in every build; only the diagnostic console.error stays behind DEBUG. Tests cover a throwing component constructor and a throwing rerender, through both the DOM and the server-side (simple-dom) delegates. They pass on development builds either way and failed on production builds before this change.
Fixes #20130