Skip to content

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

Open

Description

@yangpiao

🐞 Describe the Bug

In a Fastboot SSR app, if there's an uncaught exception when a component is rendered on server side (e.g. error in the constructor or a getter used in the template), the CURRENT_TRACKER in @glimmer/validator will not be cleaned up / de-referenced properly. As a result, it won't be collected by GC and will keep consuming the Tags from subsequent rendering. It'll keep growing until the process is killed because of OOM.

🔬 Minimal Reproduction

Repro repo: https://github.com/yangpiao/fastboot-memory-leak-repro

I tried using Ember LTS (3.28) and latest (4.5). The issue exists in both versions.

  1. yarn install.
  2. Start the server with prod build and Node debugger: node --inspect ./node_modules/.bin/ember s --environment=production. Dev build doesn't seem to have the same issue.
  3. Visit http://localhost:4200.
  4. Open Chrome DevTools for Node.js.
  5. Take a heap snapshot (optional).
    • Search for Tracker in the "Class filter" input. You won't find any Tracker in the snapshot.
  6. Visit http://localhost:4200/leak in anonther browser tab, or click the link on the page and refresh the page. The route has to be loaded and rendered on server side in Fastboot.
  7. Visit http://localhost:4200/no-leak and refresh the page. You can refresh a few more times so the leak is a bit more obvious (I refreshed about 10 times before taking the snapshot in the screenshot below). You might not be able to tell there's a leak from the heap size itself, because this website is too simple.
  8. Take another heap snapshot.
    • Search for Tracker in the "Class filter" input. You'll find some Tracker objects retained. Click on the one with the largest "retained size", and you'll find that is CURRENT_TRACKER in @glimmer/validator.

heap

😕 Actual Behavior

CURRENT_TRACKER is retained and causes memory leak. See the steps above.

🤔 Expected Behavior

Well, no memory leak.

🌍 Environment

  • Ember: 3.28, 4.5
  • Node.js/npm: 16
  • OS: MacOS, Linux
  • Browser: Any (it's in SSR)

➕ Additional Context

N/A

Activity

  1. changed the title [-][Bug] memory leak when there's an uncaught error in SSR[/-] [+][Bug] memory leak when there's an uncaught error in SSR (Fastboot)[/+] on Jun 24, 2022
  2. ariellephan commented on Jun 28, 2022

    @ariellephan

    @chriskrycho Can we tag this with "memory leak", "bug", and "has reproduction" like #20032? Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions