libxmljs2 icon indicating copy to clipboard operation
libxmljs2 copied to clipboard

Running in worker thread throws error "Module did not self-register"

Open jpdewing opened this issue 3 years ago • 3 comments

When using this package in a node worker thread it throws the error "Module did not self-register".

Reading up on this error I found some comments in the nodejs github issues log : https://github.com/nodejs/node/issues/21783#issuecomment-429637117. And more information about the c++ context aware addons can be found here https://github.com/nodejs/node/blob/master/doc/api/addons.md#context-aware-addons.

I tried the fix mentioned in this https://stackoverflow.com/questions/68598248/is-there-a-way-to-run-native-code-modules-using-worker-threads post, changing line 250 in src/libxmljs.cc from

NODE_MODULE(xmljs, init) to NAN_MODULE_WORKER_ENABLED(xmljs, init)

This does fix the problem but to be honest I don't have the expertise to understand the implications of the change. Could one of the maintainers who has a better understanding of the library look at the possibility of either introducing this change or investigating another way to make it context aware.

jpdewing avatar Mar 09 '22 18:03 jpdewing

@jpdewing thanks for the hint

Were you able to run libxmljs2 in concurrent workers though?

I have applied the fix you have suggested and it runs in a worker but when I run several workers in parallel I got errors:

# Fatal error in , line 0
# Check failed: map->instance_type() == JS_REG_EXP_TYPE || map->instance_type() == JS_OBJECT_TYPE || map->instance_type() == JS_ERROR_TYPE || map->instance_type() == JS_ARRAY_TYPE || map->instance_type() == JS_API_OBJECT_TYPE || map->instance_type() == WASM_
GLOBAL_OBJECT_TYPE || map->instance_type() == WASM_INSTANCE_OBJECT_TYPE || map->instance_type() == WASM_MEMORY_OBJECT_TYPE || map->instance_type() == WASM_MODULE_OBJECT_TYPE || map->instance_type() == WASM_TABLE_OBJECT_TYPE || map->instance_type() == JS_SPEC
IAL_API_OBJECT_TYPE.
#
#
#
#FailureMessage Object: 000000DBD4DFC9A0
 1: 00007FF7A0C45CEF napi_wrap+133327
 2: 00007FF7A0B6E9DF std::basic_ostream<char,std::char_traits<char> >::operator<<+57855
 3: 00007FF7A17E35A2 V8_Fatal+162
 4: 00007FF7A13696EE v8::internal::Factory::CopyJSObjectWithAllocationSite+1454
 5: 00007FF7A1369131 v8::internal::Factory::CopyJSObject+17
 6: 00007FF7A14D4350 v8::PropertyDescriptor::writable+10576
 7: 00007FF7A14D4665 v8::PropertyDescriptor::writable+11365
 8: 00007FF7A146FFF5 v8::internal::Builtins::builtin_handle+318933
 9: 00007FF7A14713BB v8::internal::Builtins::builtin_handle+323995
10: 00007FF7A13B2B0F v8::internal::Execution::CallWasm+831
11: 00007FF7A13B3133 v8::internal::Execution::CallWasm+2403
12: 00007FF7A14C078A v8::Function::NewInstanceWithSideEffectType+730
13: 00007FF7A14C00D0 v8::Function::NewInstance+32
14: 00007FF7A0A66CDA v8::Function::NewInstance+26
15: 00007FFFDEAA5B30 libxmljs::XmlDocument::New+336 [C:\Users\yafor\dev\libxmljs2\src\xml_document.cc]:L289
16: 00007FFFDEAA6D32 libxmljs::XmlDocument::FromXml+1394 [C:\Users\yafor\dev\libxmljs2\src\xml_document.cc]:L574
17: 00007FFFDEAA12E7 Nan::imp::FunctionCallbackWrapper+231 [C:\Users\yafor\dev\libxmljs2\node_modules\.pnpm\[email protected]\node_modules\nan\nan_callbacks_12_inl.h]:L177
18: 00007FF7A1470E3F v8::internal::Builtins::builtin_handle+322591
19: 00007FF7A14703D4 v8::internal::Builtins::builtin_handle+319924
20: 00007FF7A14706C8 v8::internal::Builtins::builtin_handle+320680
21: 00007FF7A1470513 v8::internal::Builtins::builtin_handle+320243
22: 00007FF7A154F34D v8::internal::SetupIsolateDelegate::SetupHeap+474477
23: 00007FF7A14E5432 v8::internal::SetupIsolateDelegate::SetupHeap+40530
24: 00007FF7A14E5432 v8::internal::SetupIsolateDelegate::SetupHeap+40530
25: 00007FF7A158FEC5 v8::internal::SetupIsolateDelegate::SetupHeap+739557
26: 00007FF7A14E133A v8::internal::SetupIsolateDelegate::SetupHeap+23898
27: 00007FF7A15CE413 v8::internal::SetupIsolateDelegate::SetupHeap+994867
28: 00007FF7A14E5432 v8::internal::SetupIsolateDelegate::SetupHeap+40530
29: 00007FF7A14E5432 v8::internal::SetupIsolateDelegate::SetupHeap+40530
30: 00007FF7A14E5432 v8::internal::SetupIsolateDelegate::SetupHeap+40530
31: 00007FF7A14E5432 v8::internal::SetupIsolateDelegate::SetupHeap+40530
32: 00007FF7A14E30EE v8::internal::SetupIsolateDelegate::SetupHeap+31502
33: 00007FF7A14E2CDC v8::internal::SetupIsolateDelegate::SetupHeap+30460
34: 00007FF7A13B2E42 v8::internal::Execution::CallWasm+1650
35: 00007FF7A13B26AF v8::internal::Execution::Call+191
36: 00007FF7A149E007 v8::Function::Call+615
37: 00007FF7A0C728DB node::CallbackScope::~CallbackScope+1723
38: 00007FF7A0C6A584 v8::internal::compiler::Operator::EffectOutputCount+228
39: 00007FF7A0B95725 v8::internal::AsmJsScanner::GetIdentifierString+32245
40: 00007FF7A0CA2FDB uv_async_send+331
41: 00007FF7A0CA276C uv_loop_init+1292
42: 00007FF7A0CA290A uv_run+202
43: 00007FF7A0B1E41D v8::internal::wasm::SignatureMap::Freeze+35885
44: 00007FF7A0B19D28 v8::internal::wasm::SignatureMap::Freeze+17720
45: 00007FF7A0C930ED uv_poll_stop+557
46: 00007FF7A1A49760 v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+146368
47: 00007FF84AFB7034 BaseThreadInitThunk+20
48: 00007FF84C2E2651 RtlUserThreadStart+33

vforsh avatar Jun 06 '22 13:06 vforsh

No, we ended up restructuring our code so that this library is not loaded by worker threads and is only used in the main thread. This was possible because it was other logic that we wanted to offload into the workers.

jpdewing avatar Jun 06 '22 14:06 jpdewing

I see. Unfortunately it's not an option for us since the bottleneck is libxmljs methods calls.

vforsh avatar Jun 06 '22 14:06 vforsh