Skip to content

[BUGFIX release] Reset tracking state after a render error in prod - #21634

Open
geoffroh wants to merge 3 commits into
emberjs:mainfrom
geoffroh:fix-tracking-reset-in-prod
Open

geoffroh wants to merge 3 commits into
emberjs:mainfrom
geoffroh:fix-tracking-reset-in-prod

Conversation

@geoffroh

Copy link
Copy Markdown
Contributor

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

…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
NullVoxPopuli self-requested a review September 30, 2026 01:51

@NullVoxPopuli NullVoxPopuli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're going to bring an error-recovery feature out of debug mode, and in to production, we should keep the logged message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@NullVoxPopuli

Copy link
Copy Markdown
Contributor

(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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

This branch has not been deployed

No deployments
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.

[Bug] memory leak when there's an uncaught error in SSR (Fastboot)

2 participants