Memory leak with pm2
Does anyone have any experience with deploying with pm2, this is my pm2 config. If so, could you share that? here is my config:
My deploy script runs:
Logs (from when limit was 8gb):
Logs after adding auto-restart:
module.exports = {
apps: [
{
name: "blabla",
script: "./.output/server/index.mjs",
exec_mode: "cluster",
instances: 10,
cwd: "/app",
error_file: "/app/logs/blabla-error.log",
out_file: "/app/logs/blabla-out.log",
combine_logs: true,
time: true,
autorestart: true,
max_restarts: 10,
max_memory_restart: "15360M",
node_args: "--max-old-space-size=16384 --heapsnapshot-signal=SIGUSR2", // Allocate 8 GB per instance
env: {
NODE_ENV: process.env.NODE_ENV || "production",
PORT: process.env.NITRO_PORT || 3000,
},
},
],
};module.exports = {
apps: [
{
name: "blabla",
script: "./.output/server/index.mjs",
exec_mode: "cluster",
instances: 10,
cwd: "/app",
error_file: "/app/logs/blabla-error.log",
out_file: "/app/logs/blabla-out.log",
combine_logs: true,
time: true,
autorestart: true,
max_restarts: 10,
max_memory_restart: "15360M",
node_args: "--max-old-space-size=16384 --heapsnapshot-signal=SIGUSR2", // Allocate 8 GB per instance
env: {
NODE_ENV: process.env.NODE_ENV || "production",
PORT: process.env.NITRO_PORT || 3000,
},
},
],
};My deploy script runs:
npm ci # auto runs postinstall
nuxt build npm ci # auto runs postinstall
nuxt build Logs (from when limit was 8gb):
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0xe16044 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node /app/.output/server/index.mjs]
2: 0x11e0dd0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node /app/.output/server/index.mjs]
3: 0x11e10a7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node /app/.output/server/index.mjs]
<--- Last few GCs --->
[2803716:0x1d8fd000] 3602089 ms: Scavenge 8017.8 (8212.9) -> 8008.3 (8213.4) MB, pooled: 0 MB, 21.40 / 0.02 ms (average mu = 0.186, current mu = 0.116) task;
[2803716:0x1d8fd000] 3612794 ms: Mark-Compact 8031.9 (8223.7) -> 8004.3 (8213.6) MB, pooled: 0 FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0xe16044 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node /app/.output/server/index.mjs]
2: 0x11e0dd0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node /app/.output/server/index.mjs]
3: 0x11e10a7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node /app/.output/server/index.mjs]
<--- Last few GCs --->
[2803716:0x1d8fd000] 3602089 ms: Scavenge 8017.8 (8212.9) -> 8008.3 (8213.4) MB, pooled: 0 MB, 21.40 / 0.02 ms (average mu = 0.186, current mu = 0.116) task;
[2803716:0x1d8fd000] 3612794 ms: Mark-Compact 8031.9 (8223.7) -> 8004.3 (8213.6) MB, pooled: 0 Logs after adding auto-restart:
2025-12-08T12:12:30: PM2 log: [PM2][WORKER] Process 9 restarted because it exceeds --max-memory-restart value (current_memory=16364257280 max_memory_limit=16106127360 [octets])2025-12-08T12:12:30: PM2 log: [PM2][WORKER] Process 9 restarted because it exceeds --max-memory-restart value (current_memory=16364257280 max_memory_limit=16106127360 [octets])message.txt4.12KB
message.txt4.12KB

nitro
nuxt3