카테고리 없음

[node.js] Heap Out of Memory Error

hjr067 2025. 1. 15. 10:27
$ yarn run build
yarn run build
yarn run v1.22.19
$ tsc

<--- Last few GCs --->
ll[7385:0x55e7520]    16439 ms: Mark-sweep (reduce) 486.9 (495.9) -> 485.7 (496.1) MB, 394.6 / 0.0 ms  (+ 63.3 ms in 15 steps since start of marking, biggest step 18.9 ms, walltime since start of marking 493 ms) (average mu = 0.237, current mu = 0.247) allo[7385:0x55e7520]    17047 ms: Mark-sweep (reduce) 486.7 (496.1) -> 486.1 (496.1) MB, 392.2 / 0.0 ms  (+ 57.2 ms in 14 steps since start of marking, biggest step 29.2 ms, walltime since start of marking 495 ms) (average mu = 0.248, current mu = 0.261) allo

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb0a860 node::Abort() [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
 2: 0xa1c193 node::FatalError(char const*, char const*) [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
 3: 0xcf9a6e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
 4: 0xcf9de7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
 5: 0xeb1685  [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
 6: 0xeb2166  [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
 7: 0xec068e  [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
 8: 0xec10d0 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
 9: 0xec404e v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
10: 0xe8558a v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
11: 0x11fe2d6 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
12: 0x15f2d39  [/home/ubuntu/.nvm/versions/node/v16.16.0/bin/node]
Aborted (core dumped)
error Command failed with exit code 144.

개발 도중 이런 에러가 났다 ㅎ

이건 Heap의 메모리가 부족해서 발생하는 에러라고 한다. 

 

1) 일단, 간단한 해결 방법으로는 메모리 할당량을 늘려주면 된다.

내가 지금 그걸로 해결하긴 했는데, 실행시킬 때 

node --max-old-space-size=12000 dist/scheduler/allam/cardMessage.js

이런식으로 할당량을 늘려주는 것이다. 

 

** 매번 서버를 재배포할 때마다 터미널에 위 코드를 입력하는게 번거롭다면, .bashrc 파일에 위의 용량 늘리는 코드를 그대로 추가하면 된당 !

 

2) 근본적인 문제 해결

이 에러는 어딘가에서 메모리 누수가 있기에 발생하는 에러일수도 있다.

그래서 메모리 누수 검사를 해보아야 한다.

 

++ 나중에 이어서 쓰기