0

I am facing an issue where node application crashes when OS sends SIGPIPE. I am using N-API C++ addon for sending/receiving message to socket using Function Callbacks. is there any way to find the root cause or handle the same so that app does not crashes or prevent the issue by finding root cause?

below is the stack trace for the same

Walk Stack Trace Size=[14]
[0x5d171e0]
/lib64/libpthread.so.0(+0xf5e0) [0x7fc924a935e0]
/lib64/libc.so.6(writev+0x60) [0x7fc9247b0230]
/home/panadmin/bin/node() [0x1386621]
/home/panadmin/bin/node(uv_write2+0x203) [0x13878a3]
/home/panadmin/bin/node(uv_try_write+0x6d) [0x1387b7d]
/home/panadmin/bin/node(_ZThn88_N4node15LibuvStreamWrap10DoTryWriteEPP8uv_buf_tPm+0x26) [0xadace6]
/home/panadmin/bin/node(_ZN4node10StreamBase6WritevERKN2v820FunctionCallbackInfoINS1_5ValueEEE+0x322) [0xad11d2]
/home/panadmin/bin/node(_ZN4node10StreamBase8JSMethodIXadL_ZNS0_6WritevERKN2v820FunctionCallbackInfoINS2_5ValueEEEEEEEvS7_+0xa0) [0xad37f0]
/home/panadmin/bin/node() [0xbe456b]
/home/panadmin/bin/node() [0xbe5b16]
/home/panadmin/bin/node(_ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE+0x16) [0xbe6196]
/home/panadmin/bin/node() [0x1400119]
Segmentation violation occured
Walk Stack Trace Size=[16]
[0x5d171e0]
/lib64/libpthread.so.0(+0xf5e0) [0x7fc924a935e0]
/lib64/libpthread.so.0(pthread_mutex_lock+0) [0x7fc924a8dc30]
/home/panadmin/bin10.14.0.0.SP5/Framework/cim_addons/pm/Release/pm_interface.node(_ZN4PLog12flush_outputEv+0x1c) [0x7fc8f43a1d52]
/home/panadmin/bin10.14.0.0.SP5/Framework/cim_addons/pm/Release/pm_interface.node(_ZN10PAppLogger12flush_outputEv+0x16) [0x7fc8f43a13ee]
/home/panadmin/bin10.14.0.0.SP5/Framework/cim_addons/pm/Release/pm_interface.node(_Z17linux_sig_handleri10sigcontext+0x125) [0x7fc8f43a11e7]
/lib64/libpthread.so.0(+0xf5e0) [0x7fc924a935e0]
/lib64/libc.so.6(writev+0x60) [0x7fc9247b0230]
/home/panadmin/bin/node() [0x1386621]
/home/panadmin/bin/node(uv_write2+0x203) [0x13878a3]
/home/panadmin/bin/node(uv_try_write+0x6d) [0x1387b7d]
/home/panadmin/bin/node(_ZThn88_N4node15LibuvStreamWrap10DoTryWriteEPP8uv_buf_tPm+0x26) [0xadace6]
/home/panadmin/bin/node(_ZN4node10StreamBase6WritevERKN2v820FunctionCallbackInfoINS1_5ValueEEE+0x322) [0xad11d2]
/home/panadmin/bin/node(_ZN4node10StreamBase8JSMethodIXadL_ZNS0_6WritevERKN2v820FunctionCallbackInfoINS2_5ValueEEEEEEEvS7_+0xa0) [0xad37f0]
/home/panadmin/bin/node() [0xbe456b]
  • Try compiling both Node and your addon in Debug mode and running them in a debugger (such as GDB). – jmrk Jul 07 '22 at 08:40
  • @jmrk the issue is occurring in production environment where we cannot debug like that and in local it is not reproducing. something to do with the environment is causing the issue. will strace help? – Narendra Regar Jul 07 '22 at 08:55
  • I don't know what will help. When something crashes, your task is to understand what's going wrong, by whatever means necessary. It may well be that figuring out how to reproduce this in a debuggable environment is 80% of the work, and fixing it will then be easy in comparison... it may also be that you find a way to understand what's happening without catching the issue in a debugger. – jmrk Jul 07 '22 at 09:27
  • Build the application with debug symbols and make it so it writes a `core` dump when it crashes. If you can afford it, build it with `-O0`. Also, a crash in `uv_write` is probably caused by trying to read from a buffer that has already been deallocated. – mmomtchev Jul 30 '22 at 17:24

1 Answers1

0

Verify whether the PIC (Position Independent Code) setting while building the native module is ON or not. If it is currently off, then try setting it ON and then re-build the package. If you are using Cmake.js then you could use the following setting.

set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
Satyan
  • 1,346
  • 8
  • 15