node js application is crashing in uv_try_write while using N-API C++ addon on SIGPIPE. how can I handle/prevent the issue?

105 Views Asked by At

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]
1

There are 1 best solutions below

0
Satyan On

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)