Skip to content

Fix memory leak caused by initializing applicationinsights-web during SSR#2

Open
jrskerritt wants to merge 1 commit intoCMeeg:mainfrom
jrskerritt:fix-memory-leak
Open

Fix memory leak caused by initializing applicationinsights-web during SSR#2
jrskerritt wants to merge 1 commit intoCMeeg:mainfrom
jrskerritt:fix-memory-leak

Conversation

@jrskerritt
Copy link

Hi there!

First off, thank you for this template. It helped me out a lot when I was first setting up a Remix application that runs in Azure.

The app had trouble from the beginning with some intermittent poor performance, and as we started getting low amounts traffic, we noticed that it was becoming a regular problem, requiring us to restart our App Service frequently (eventually on a nightly basis).

Finally, I was able to identify the root cause of these issues - there is a memory leak that is caused by the applicationinsights-web client being initialized during SSR:

Screenshot 2025-01-31 at 3 52 52 PM

The problem lies in Context.tsx, where loadAppInsights is called on the server when it doesn't need to be.

I made a similar change to this PR in my own application that fixes the leak. It simply moves the initialization to a useEffect hook, ensuring it is only called on the client.

@gvillo
Copy link

gvillo commented Mar 27, 2025

@jrskerritt I would like to say thank you so much for this, I've implemented your changes and I noticed huge improvements in our container
image

I highly recommend applying this patch ASAP.

cc @CMeeg

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