node-segfault-handler icon indicating copy to clipboard operation
node-segfault-handler copied to clipboard

Is the register handler callback broken?

Open binarykitchen opened this issue 8 years ago • 7 comments

    SegfaultHandler.registerHandler('crash.log', function(signal, address, stack) {
        console.log('here!')
    })

    SegfaultHandler.causeSegfault()

here! is never printed. A bug or am I doing something wrong?

binarykitchen avatar Apr 04 '16 11:04 binarykitchen

Also seeing the same.

bfabec avatar Feb 06 '17 13:02 bfabec

same here

its always crashing in

nan_callbacks_12_inl.h (175): Nan::imp::FunctionCallbackWrapper

(well the stacktrace is even in the readme.. ^^)

a-teammate avatar Jun 28 '17 22:06 a-teammate

Okay, its probably just bc im on windows.. furthermore @bfabec and @binarykitchen i just noticed the npm version is 1.0 which did not contain that handler.

@ddopson, @No9 are there any plans for version 1.1?

To get the overriden handler working on windows we need two things:

  1. get the stacktrace into an array
  2. find a pthread replacement for windows

Solutions:

  1. could be taken from https://github.com/inexorgame-obsolete/platform/blob/master/include/windows/StackWalker%2B%2B/StackWalker.h
  2. could be replace with std::mutex or the winapi maybe

I'd be willing to do this using the stdlib with c++11, since I don't know and neither want to use the windows specific mutex stuff. thoughts?

EDIT:

I just found about v8::Locker , see https://nodeaddons.com/how-not-to-access-node-js-from-c-worker-threads/:

Since we do not need simultaneous access from multiple threads for our crash handler (or do we @lavarsicious?) we could use that or cant we?

Imo we would only need it if: different native modules crash at the very same time (or other: in the time the callback is running the next native module crashes)

a-teammate avatar Jun 30 '17 03:06 a-teammate

Still seems to be an issue.

The callback is never called.

import segfaultHandler from 'segfault-handler';
segfaultHandler.registerHandler('/var/log/unraid-api/crash.log', (signal, address, stack) => JSON.stringify({ signal, address, stack }));

OmgImAlexis avatar Jun 22 '22 22:06 OmgImAlexis

As the application is crashed at that point I don't think stdout is still hooked up so console.log won't work. I found if you use writeFileSync you can write before the app completely stops like so.

This way we get both the human readable and the raw output.

import { writeFileSync } from 'fs';
import segfaultHandler from 'segfault-handler';
segfaultHandler.registerHandler('/var/log/app-name/crash.log', (signal, address, stack) => {
	writeFileSync('/var/log/app-name/crash.json', JSON.stringify({ signal, address, stack }));
});

OmgImAlexis avatar Jun 28 '22 21:06 OmgImAlexis

Hi, I need someone else to volunteer to maintain this module. I no longer have Node.js installed, and I haven't been paying attention to this space for many years. If someone would like to volunteer for this, please let me know.

ddopson avatar Jul 03 '22 22:07 ddopson

I'd be happy to help but I don't think if I know enough C++ as I'm mainly a node/python dev.

OmgImAlexis avatar Jul 03 '22 22:07 OmgImAlexis