Next.js 15 App Router: Memory Leak Leading to OOM (Exit 137) in Production - Zustand Store Cleanup Issue #86820
Unanswered
vishwas-fab
asked this question in
Help
Replies: 1 comment
-
|
Mmm wait what is happening here? let apiStore: UseBoundStore<StoreApi<PdpApiState>> | null = null;
export const createPdpApiStore = (initialData, isLoggedIn) => {
apiStore = create<PdpApiState>((set, get) => ({
propertyDetailsData: initialData, // Large object ~200KB
checkoutDetailsData: null,
// ... more state
}));
return apiStore;
};Doesn't this mean apiStore is effectively shared by all users? This feels weird, where did you get this pattern from? I guess one could say, well do I think you need defer initializing the store until you are fully client side. Just send the initial inputs to the client, anything but the global singleton. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hi everyone,
I'm experiencing a critical memory leak in production with Next.js 15.3.3 (App Router) that's causing OOM kills (Exit Code 137) on GKE. Looking for advice on proper cleanup patterns.
Environment:
--max-old-space-size=2048)The Problem:
Pods restart with Exit Code 137 (OOM kill) after 5-11 hours of runtime. The pattern is consistent and accelerating (was 11 hours, now down to 5 hours).
Symptoms:
Architecture:
We have a property detail page (PDP) that:
Suspected Root Cause:
The Issue:
Each PDP page view creates a new store, but the old store reference persists in memory. With ~15,000 requests over 5-11 hours, this accumulates to 3GB+.
Questions:
Is this the correct pattern for Zustand in Next.js App Router? Should stores be module-level or created differently?
How should I properly clean up Zustand stores in SSR context? I'm thinking:
Then call this in a
useEffectcleanup:Are there better patterns for managing state in high-traffic SSR apps? Should I avoid module-level stores entirely?
Could Next.js caching be contributing? We're using
output: 'standalone'and have fetch calls with default caching.What I've Tried:
unoptimized: true)Additional Context:
Any advice on:
Thanks in advance!
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions