9

is it possible to inspect the javascript stack trace when node.js goes in Segmentation fault?

The current situation is the following: I am running a script which has a few nested async.eachSeries, which caused for some weird reason a RangeError: Maximum call stack size exceeded. Hence, I have increased the stack size via node --stack-size=1000000 and I am left with the Segmentation fault.

Here is the source code of the script: http://nopaste.info/ca0c118591.html

Update

I also tried segfault-handler, but for some inscrutable reason it is not catching my segfault.

fstab
  • 4,801
  • 8
  • 34
  • 66

2 Answers2

2

There is the segfault-handler module which catches segfaults on non-Windows platforms and generates a stack trace. But if you're getting a RangeError, that's not a segfault.

mscdex
  • 104,356
  • 15
  • 192
  • 153
  • segfault after increasing the stack-size and 'solving' the `RangeError` – fstab Dec 05 '14 at 13:38
  • 2
    It's very strange. `segfault-handler` correctly handles its own test segmentation fault function `SegfaultHandler.causeSegfault()`, but not my actual bug. – fstab Dec 05 '14 at 13:43
2

This likely means you have recursivety somewhere in your code. Since V8 removed support for TCO (Tail Call Optimization) the call size will grow until it explodes.

Using --stack_size would seem like a natural solution, but it doesn't actually increase the stack size, it is tells V8 to assume there is a bigger stack size when in reality this is controlled by the OS.

Sources:

So for now ( with Node.js 8.x ) the best solution is simple to stop using recursive functions.

Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266