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

Possible memory-leak within ui-angular#AuthenticatorService (Angular SSR) #6293

Open
4 tasks done
QuentinFchx opened this issue Jan 10, 2025 · 4 comments
Open
4 tasks done
Labels
Angular An issue or a feature-request for Angular platform Authenticator An issue or a feature-request for an Authenticator UI Component bug Something isn't working

Comments

@QuentinFchx
Copy link
Contributor

QuentinFchx commented Jan 10, 2025

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

Angular

Which UI component?

Authenticator, Primitive components

How is your app built?

@angular/cli

What browsers are you seeing the problem on?

No response

Which region are you seeing the problem in?

No response

Please describe your bug.

I'm using the AmplifyUI library within a server-side rendered Angular application.
I'm seeing a constant memory increase on the machines running the server code until they crash
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory.

After some quick fiddling with the Chrome memory profiler, I strongly suspect something in the amplify-related packages to trigger the issue.
Please note that I'm not very proficient with heap snapshots interpretation.

What's the expected behaviour?

No memory leak

Help us reproduce the bug!

I've created a repository that reproduces the bug https://github.com/QuentinFchx/amplify-leak

ng build
node --inspect dist/amplify-leak/server/server.mjs

Open chrome://inspect
Go to localhost:4000 (refresh 1-2 times to warm the server)
Take a heap snapshot
curl http://localhost:4000\?\[1-100\] (perform 100 requests)
Take another heap snapshot

-> The memory constantly increases

Please note that :

  • I disabled the pre-rendering "prerender": false
  • The leak does not happen if I don't initialize the AuthenticatorService (remove the line private authenticator = inject(AuthenticatorService);)

Code Snippet

No response

Console log output

No response

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify UI maintainer labels Jan 10, 2025
@cwomack
Copy link
Member

cwomack commented Jan 10, 2025

Hello, @QuentinFchx and thank you for opening this issue. Greatly appreciate the sample repo and we'll investigate this/follow up with any additional questions we have.

@cwomack cwomack added Angular An issue or a feature-request for Angular platform Authenticator An issue or a feature-request for an Authenticator UI Component labels Jan 10, 2025
@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify UI maintainer label Jan 10, 2025
@cwomack cwomack added bug Something isn't working and removed pending-triage Issue is pending triage labels Jan 13, 2025
@tiffanynwyeung
Copy link
Member

@QuentinFchx Hello, thanks for reaching out about this issue 👋 We suggest that the service should be used together with the Authenticator UI component. Can you clarify if you still experience this memory leak issue if you render the UI component?

@QuentinFchx
Copy link
Contributor Author

QuentinFchx commented Jan 19, 2025

Hello, sorry for the late answer

To make sure we're talking about the same thing, do you agree this is the suggested approach :

import { Component, inject } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import {
  AmplifyAuthenticatorModule,
  AuthenticatorService,
} from '@aws-amplify/ui-angular';

@Component({
  selector: 'app-root',
  imports: [RouterOutlet, AmplifyAuthenticatorModule], // import the module here
  providers: [AuthenticatorService],
  template: `
    <h1>Leak repro</h1>

    <p>Hello, world</p>

   <!-- Use the component here -->
    <amplify-authenticator></amplify-authenticator> 

    <router-outlet />
  `,
  styleUrl: './app.component.css',
})
export class AppComponent {
  private authenticator = inject(AuthenticatorService);

  title = 'amplify-leak';
}

If yes, I do observe a memory leak with this configuration.
I just wanted to reduce the code to its minimum to ease the reproduction of the issue :)

Here is a screenshot of my profiler (snapshot 1 after 2 requests, snapshot 2 after 102 requests)
Image

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify UI maintainer label Jan 19, 2025
@cwomack
Copy link
Member

cwomack commented Jan 22, 2025

@QuentinFchx, appreciate all the detailed screenshots and context you replied with. We've been able to reproduce this consistently on our side and the memory leak seems to only happen when using SSR, but not happening when using the Authenticator component client side.

As we continue to investigate the root cause here, we'll follow up if there's any workarounds we can recommend until a fix is in place.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify UI maintainer label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Angular An issue or a feature-request for Angular platform Authenticator An issue or a feature-request for an Authenticator UI Component bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants