SAP / node-rfc

Asynchronous, non-blocking SAP NW RFC SDK bindings for Node.js
Apache License 2.0
251 stars 73 forks source link

wrapString fatal error (core dumped) #151

Closed SchroterQuentin closed 4 years ago

SchroterQuentin commented 4 years ago

I'm facing an issue which appear some times but not every times.

FATAL ERROR: wrapString fatal error: length: 8 utf8Size: 48 resultLen: 0 node-rfc internal error
 1: 0x8fb090 node::Abort() [node]
 2: 0x8fb0dc  [node]
 3: 0x8fdc59  [node]
 4: 0x90a24b napi_fatal_error [node]
 5: 0x7ffae2a58c36  [/home/laura/Documents/test/mercure/depends/Heimdall/node_modules/node-rfc/lib/binding/sapnwrfc.node]
 6: 0x7ffae2a6c356 node_rfc::wrapString(char16_t*, int) [/home/laura/Documents/test/mercure/depends/Heimdall/node_modules/node-rfc/lib/binding/sapnwrfc.node]
 7: 0x7ffae2a65846 node_rfc::Client::wrapVariable(_RFCTYPE, RFC_DATA_CONTAINER*, char16_t*, unsigned int, _RFC_TYPE_DESC_HANDLE*) [/home/laura/Documents/test/mercure/depends/Heimdall/node_modules/node-rfc/lib/binding/sapnwrfc.node]
 8: 0x7ffae2a684ec node_rfc::Client::wrapResult(_RFC_FUNCTION_DESC_HANDLE*, RFC_DATA_CONTAINER*) [/home/laura/Documents/test/mercure/depends/Heimdall/node_modules/node-rfc/lib/binding/sapnwrfc.node]
 9: 0x7ffae2a64711 node_rfc::InvokeAsync::OnOK() [/home/laura/Documents/test/mercure/depends/Heimdall/node_modules/node-rfc/lib/binding/sapnwrfc.node]
10: 0x7ffae2a63481 Napi::AsyncWorker::OnWorkComplete(napi_env__*, napi_status, void*) [/home/laura/Documents/test/mercure/depends/Heimdall/node_modules/node-rfc/lib/binding/sapnwrfc.node]
11: 0x906ced  [node]
12: 0xa6cb55  [node]
13: 0xa71041  [node]
14: 0xa83968  [node]
15: 0xa719cb uv_run [node]
16: 0x905535 node::Start(v8::Isolate*, node::IsolateData*, std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&) [node]
17: 0x90379f node::Start(int, char**) [node]
18: 0x7ffafa943b97 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
19: 0x8bce95  [node]
Aborted (core dumped)
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! connector@1.0.0 start: `npm run build && node dist/app.js`
npm ERR! Exit status 134
npm ERR! 
npm ERR! Failed at the connector@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Do you have any idea what may cause this crash ? What kind of informations do you need ?

bsrdjan commented 4 years ago

Could you please let me know the node-rfc version and SAP NWRFC SDK version? I would like to add some more information to error log.

Do you maybe know which ABAP RFC is called, raising this condition?

SchroterQuentin commented 4 years ago

Yes sure. We are using node-rfc 1.0.6 with the 7.50 NWRFC SDK.

We are actually calling the BAPI ZARTICLE which is a custom BAPI my boss wrote and I may find you the import and result definition for this BAPI if you need it ?

bsrdjan commented 4 years ago

The import and result definition could help if not many parameters and/or complex data structures in this RFM (Remote Function Module). What is missing in node-rfc are more error info and more info about parameter/field causing this error. Is it possible to reproduce the error, with specific set of input parameters?

SchroterQuentin commented 4 years ago

Here comes the definition (the description is in french, sorry), if you need anything else, just ask. I upgraded the connector to use the 1.2.0 release and I didn't get any issue since. I'm still getting a lot of segfault but we are not using the pool of connection and making a lot of connection in the same time for the same user with one connection per BAPI call ; which is certainly an incorrect use of the sdk.

image image

I'm wondering why there is segfault with the node-rfc connector and not the pyRFC connector ?

bsrdjan commented 4 years ago

When the wrapString fails, the fatal error is raised because of the assumption that if wrapString does not work, then the regular error info can't be "wrapped" into standard node-rfc error. That assumption from the node-rfc early days is no longer valid. The wrapString logic is quite stable and the error in wrapString should be propagated as a standard error. That needs to be changed in the next release.

Two types of errors can happen here:

1) Conversion buffer too small, which is not the case here. Based on error log, the ABAP field unicode length is 8 and 48 bytes are allocated for the conversion. 6 bytes per unicode symbol should be enough

2) SAP_CHAR value can't be converted to UTF-8. It could be for example an (int) value or surrogate halve not used in Unicode, or sequence corrupted some other way. That is what more likely happens here but without error log only guessing. Why PyRFC works different, need to check, after finding out which behaviour is correct -> depending on whether the ABAP value is correct unicode or not.

If possible to reproduce this error without huge amount of RFC calls, you could activate the RFC trace and send me the trace files after the error happens?

In sapnwrfc.ini file the default trace level shall be set to "3" and also for the destination set to "3". Something like:

DEFAULT
RFC_TRACE=3

DEST=MME
USER=demo
PASSWD=welcome
ASHOST=10.68.110.51
SYSNR=00
CLIENT=620
LANG=EN
TRACE=3
bsrdjan commented 4 years ago

Instead of fatal error, an nodeRfcError is now raised, with the message ABAP string could not be parsed to unicode and with rfmPath pointing to affected field. Please feel free to try with 2.0.2 release.