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

Report Out of memory fatal error to Sentry #4148

Closed
LukasHirt opened this issue Apr 19, 2023 · 5 comments
Closed

Report Out of memory fatal error to Sentry #4148

LukasHirt opened this issue Apr 19, 2023 · 5 comments

Comments

@LukasHirt
Copy link

LukasHirt commented Apr 19, 2023

Details

Lately I was repeatedly experiencing Out of memory issues in one project and I was hoping to report this error into my Sentry org. I tried using process.on with various events (e.g. exit) but none of them were calling their listeners once the error happens.

Is there any way to actually call a function on fatal error before the process is shutdown? I do not want to prevent the process, only send message to Sentry.

Node.js version

v16.18.1

Example code

The OOM error:

<--- Last few GCs --->

[30886:0x7fc6ab300000]     4257 ms: Mark-sweep (reduce) 98.5 (104.2) -> 97.1 (104.2) MB, 40.1 / 0.0 ms  (average mu = 0.278, current mu = 0.240) allocation failure scavenge might not succeed
[30886:0x7fc6ab300000]     4298 ms: Mark-sweep (reduce) 98.4 (104.5) -> 97.2 (104.5) MB, 30.5 / 0.1 ms  (average mu = 0.272, current mu = 0.264) allocation failure scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x105d985f5 node::Abort() (.cold.1) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
 2: 0x104a8df49 node::Abort() [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
 3: 0x104a8e12e node::OOMErrorHandler(char const*, bool) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
 4: 0x104c053f0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
 5: 0x104c053b3 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
 6: 0x104da9095 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
 7: 0x104dad0dd v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
 8: 0x104da99bd v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
 9: 0x104da6edd v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
10: 0x104db42c0 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
11: 0x104db4341 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
12: 0x104d813d7 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
13: 0x105138ece v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
14: 0x1054e1c19 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
15: 0x105484b0a Builtins_StoreFastElementIC_GrowNoTransitionHandleCOW [/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node]
16: 0x109dce922

Operating system

macOS Ventura v13.2.1

Scope

runtime

Module and version

Not applicable.

@AtillaPehlivan
Copy link

Hi @LukasHirt, maybe you can use https://github.com/lloyd/node-memwatch package

Leak Detection
You can then subscribe to leak events. A leak event will be emitted when your heap usage has increased for five consecutive garbage collections:

memwatch.on('leak', function(info) { ... });

@LukasHirt
Copy link
Author

maybe you can use https://github.com/lloyd/node-memwatch package

Thank you @AtillaPehlivan for the hint. I already tried this package but unfortunately have an error when trying to install the package via npm. Maybe I'll try to spend some time trying to getting it to work.

npm ERR! code 1
npm ERR! path /Users/lukashirt/Work/playeur/web/node_modules/memwatch
npm ERR! command failed
npm ERR! command sh -c -- node-gyp rebuild
npm ERR! CXX(target) Release/obj.target/memwatch/src/heapdiff.o
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | x64
npm ERR! gyp info find Python using Python version 3.9.6 found at "/Applications/Xcode.app/Contents/Developer/usr/bin/python3"
npm ERR! gyp info spawn /Applications/Xcode.app/Contents/Developer/usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/Users/lukashirt/.nvm/versions/node/v16.18.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/lukashirt/Work/playeur/web/node_modules/memwatch/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/lukashirt/.nvm/versions/node/v16.18.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/lukashirt/Library/Caches/node-gyp/16.18.1/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/lukashirt/Library/Caches/node-gyp/16.18.1',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/lukashirt/.nvm/versions/node/v16.18.1/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/lukashirt/Library/Caches/node-gyp/16.18.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/lukashirt/Work/playeur/web/node_modules/memwatch',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from ../src/heapdiff.cc:5:
npm ERR! ../src/heapdiff.hh:14:35: error: expected class name
npm ERR!     class HeapDiff : public node::ObjectWrap
npm ERR!                                   ^
npm ERR! ../src/heapdiff.hh:17:38: error: no template named 'Handle' in namespace 'v8'
npm ERR!         static void Initialize ( v8::Handle<v8::Object> target );
npm ERR!                                  ~~~~^
npm ERR! ../src/heapdiff.hh:19:20: error: no template named 'Handle' in namespace 'v8'
npm ERR!         static v8::Handle<v8::Value> New( const v8::Arguments& args );
npm ERR!                ~~~~^
npm ERR! ../src/heapdiff.hh:19:53: error: no type named 'Arguments' in namespace 'v8'
npm ERR!         static v8::Handle<v8::Value> New( const v8::Arguments& args );
npm ERR!                                                 ~~~~^
npm ERR! ../src/heapdiff.hh:20:20: error: no template named 'Handle' in namespace 'v8'
npm ERR!         static v8::Handle<v8::Value> End( const v8::Arguments& args );
npm ERR!                ~~~~^
npm ERR! ../src/heapdiff.hh:20:53: error: no type named 'Arguments' in namespace 'v8'
npm ERR!         static v8::Handle<v8::Value> End( const v8::Arguments& args );
npm ERR!                                                 ~~~~^
npm ERR! ../src/heapdiff.cc:30:34: error: member initializer 'ObjectWrap' does not name a non-static data member or base class
npm ERR! heapdiff::HeapDiff::HeapDiff() : ObjectWrap(), before(NULL), after(NULL),
npm ERR!                                  ^~~~~~~~~~~~
npm ERR! ../src/heapdiff.cc:49:21: error: variable has incomplete type 'void'
npm ERR! heapdiff::HeapDiff::Initialize ( v8::Handle<v8::Object> target )
npm ERR!                     ^
npm ERR! ../src/heapdiff.cc:49:55: error: expected '(' for function-style cast or type construction
npm ERR! heapdiff::HeapDiff::Initialize ( v8::Handle<v8::Object> target )
npm ERR!                                             ~~~~~~~~~~^
npm ERR! ../src/heapdiff.cc:49:38: error: no member named 'Handle' in namespace 'v8'
npm ERR! heapdiff::HeapDiff::Initialize ( v8::Handle<v8::Object> target )
npm ERR!                                  ~~~~^
npm ERR! ../src/heapdiff.cc:49:57: error: use of undeclared identifier 'target'
npm ERR! heapdiff::HeapDiff::Initialize ( v8::Handle<v8::Object> target )
npm ERR!                                                         ^
npm ERR! ../src/heapdiff.cc:49:65: error: expected ';' after top level declarator
npm ERR! heapdiff::HeapDiff::Initialize ( v8::Handle<v8::Object> target )
npm ERR!                                                                 ^
npm ERR!                                                                 ;
npm ERR! ../src/heapdiff.cc:124:14: error: unknown type name 'idset'
npm ERR! void setDiff(idset a, idset b, vector<uint64_t> &c)
npm ERR!              ^
npm ERR! ../src/heapdiff.cc:124:23: error: unknown type name 'idset'
npm ERR! void setDiff(idset a, idset b, vector<uint64_t> &c)
npm ERR!                       ^
npm ERR! ../src/heapdiff.cc:126:10: error: use of undeclared identifier 'idset'
npm ERR!     for (idset::iterator i = a.begin(); i != a.end(); i++) {
npm ERR!          ^
npm ERR! ../src/heapdiff.cc:174:25: error: use of undeclared identifier 'handleToStr'
npm ERR!             type.append(handleToStr(node->GetName()));
npm ERR!                         ^
npm ERR! ../src/heapdiff.cc:202:29: error: no member named 'GetSelfSize' in 'v8::HeapGraphNode'
npm ERR!     i->second.size += node->GetSelfSize() * (added ? 1 : -1);
npm ERR!                       ~~~~  ^
npm ERR! ../src/heapdiff.cc:211:8: error: no template named 'Handle'
npm ERR! static Handle<Value> changesetToObject(changeset & changes)
npm ERR!        ^
npm ERR! ../src/heapdiff.cc:213:21: error: calling a protected constructor of class 'v8::HandleScope'
npm ERR!     v8::HandleScope scope;
npm ERR!                     ^
npm ERR! /Users/lukashirt/Library/Caches/node-gyp/16.18.1/include/node/v8.h:1232:13: note: declared protected here
npm ERR!   V8_INLINE HandleScope() = default;
npm ERR!             ^
npm ERR! fatal error: too many errors emitted, stopping now [-ferror-limit=]
npm ERR! 20 errors generated.
npm ERR! make: *** [Release/obj.target/memwatch/src/heapdiff.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/Users/lukashirt/.nvm/versions/node/v16.18.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:201:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
npm ERR! gyp ERR! System Darwin 22.4.0
npm ERR! gyp ERR! command "/Users/lukashirt/.nvm/versions/node/v16.18.1/bin/node" "/Users/lukashirt/.nvm/versions/node/v16.18.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/lukashirt/Work/playeur/web/node_modules/memwatch
npm ERR! gyp ERR! node -v v16.18.1
npm ERR! gyp ERR! node-gyp -v v9.1.0
npm ERR! gyp ERR! not ok

@risalfajar
Copy link

This happens to me using Sentry SvelteKit integration

[sentry-vite-plugin] Info: Successfully uploaded source maps.
[sentry-vite-plugin] Info: Successfully finalized release.

<--- Last few GCs --->

[56283:0x5ec5b60]    32231 ms: Scavenge 4041.9 (4122.3) -> 4041.7 (4127.8) MB, 5.4 / 0.0 ms  (average mu = 0.298, current mu = 0.162) allocation failure; 
[56283:0x5ec5b60]    32272 ms: Scavenge 4048.3 (4132.5) -> 4048.2 (4134.0) MB, 5.0 / 0.0 ms  (average mu = 0.298, current mu = 0.162) allocation failure; 
[56283:0x5ec5b60]    33675 ms: Mark-sweep 4060.4 (4142.8) -> 4056.3 (4151.1) MB, 1395.5 / 0.0 ms  (average mu = 0.183, current mu = 0.050) allocation failure; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb83f50 node::Abort() [node]
 2: 0xa94834  [node]
 3: 0xd647c0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xd64b67 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xf42265  [node]
 6: 0xf5474d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 7: 0xf2ee4e v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 8: 0xf30217 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 9: 0xf113ea v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
10: 0x12d674f v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
11: 0x17035b9  [node]
Aborted (core dumped)

Copy link

github-actions bot commented May 7, 2024

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment.
If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
Make sure to look at the README file for the most updated links.

@github-actions github-actions bot added the stale label May 7, 2024
Copy link

github-actions bot commented Jun 7, 2024

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment.
If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
Make sure to look at the README file for the most updated links.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants