Closed viferga closed 1 year ago
here's the output from valgrind
λ exit
==124538== ----------------------------------------------------------------
==124538==
==124538== Lock at 0x4EE2180 was first observed
==124538== at 0x4843D9D: pthread_mutex_init (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x7ABB4B5: v8::base::RecursiveMutex::RecursiveMutex() (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x72840CA: v8::internal::Isolate::Isolate(std::unique_ptr<v8::internal::IsolateAllocator, std::default_delete<v8::internal::IsolateAllocator> >, bool) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x7284CED: v8::internal::Isolate::Allocate(bool) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x673CB24: node::NodeMainInstance::NodeMainInstance(node::SnapshotData const*, uv_loop_s*, node::MultiIsolatePlatform*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x66ABF48: node::Start(int, char**) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x5A42DB1: node_loader_impl_thread(void*) (node_loader_impl.cpp:4189)
==124538== by 0x4842B1A: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x4AA7608: start_thread (pthread_create.c:477)
==124538== by 0x4BE3162: clone (clone.S:95)
==124538== Address 0x4ee2180 is 54,624 bytes inside a block of size 60,536 alloc'd
==124538== at 0x483CF03: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x73D75F9: v8::internal::IsolateAllocator::IsolateAllocator() (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x7284CD6: v8::internal::Isolate::Allocate(bool) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x673CB24: node::NodeMainInstance::NodeMainInstance(node::SnapshotData const*, uv_loop_s*, node::MultiIsolatePlatform*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x66ABF48: node::Start(int, char**) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x5A42DB1: node_loader_impl_thread(void*) (node_loader_impl.cpp:4189)
==124538== by 0x4842B1A: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x4AA7608: start_thread (pthread_create.c:477)
==124538== by 0x4BE3162: clone (clone.S:95)
==124538== Block was alloc'd by thread #2
==124538==
==124538== Lock at 0x4EC7338 was first observed
==124538== at 0x4843D9D: pthread_mutex_init (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x6C518DE: uv_mutex_init (thread.c:284)
==124538== by 0x5A5081A: node_loader_impl_initialize (node_loader_impl.cpp:4309)
==124538== by 0x48767E1: loader_impl_initialize.part.0 (loader_impl.c:367)
==124538== by 0x4876B15: loader_impl_initialize (loader_impl.c:887)
==124538== by 0x4876B15: loader_impl_load_from_file (loader_impl.c:822)
==124538== by 0x48751FC: loader_load_from_configuration (loader.c:475)
==124538== by 0x521BC94: plugin_load_from_path(unsigned long, void**, void*) (plugin_extension.cpp:92)
==124538== by 0x48795AD: metacallfv_s (metacall.c:1025)
==124538== by 0x10CBA5: metacallcli::application::application(int, char**) (application.cpp:182)
==124538== by 0x10BEDD: main (main.cpp:35)
==124538== Address 0x4ec7338 is 328 bytes inside a block of size 728 alloc'd
==124538== at 0x483CF03: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x5A50789: node_loader_impl_initialize (node_loader_impl.cpp:4267)
==124538== by 0x48767E1: loader_impl_initialize.part.0 (loader_impl.c:367)
==124538== by 0x4876B15: loader_impl_initialize (loader_impl.c:887)
==124538== by 0x4876B15: loader_impl_load_from_file (loader_impl.c:822)
==124538== by 0x48751FC: loader_load_from_configuration (loader.c:475)
==124538== by 0x521BC94: plugin_load_from_path(unsigned long, void**, void*) (plugin_extension.cpp:92)
==124538== by 0x48795AD: metacallfv_s (metacall.c:1025)
==124538== by 0x10CBA5: metacallcli::application::application(int, char**) (application.cpp:182)
==124538== by 0x10BEDD: main (main.cpp:35)
==124538== Block was alloc'd by thread #1
==124538==
==124538== Lock at 0x4EE4A30 was first observed
==124538== at 0x4843D9D: pthread_mutex_init (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x729DF65: v8::internal::ThreadManager::ThreadManager(v8::internal::Isolate*) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x7284987: v8::internal::Isolate::Isolate(std::unique_ptr<v8::internal::IsolateAllocator, std::default_delete<v8::internal::IsolateAllocator> >, bool) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x7284CED: v8::internal::Isolate::Allocate(bool) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x673CB24: node::NodeMainInstance::NodeMainInstance(node::SnapshotData const*, uv_loop_s*, node::MultiIsolatePlatform*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x66ABF48: node::Start(int, char**) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x5A42DB1: node_loader_impl_thread(void*) (node_loader_impl.cpp:4189)
==124538== by 0x4842B1A: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x4AA7608: start_thread (pthread_create.c:477)
==124538== by 0x4BE3162: clone (clone.S:95)
==124538== Address 0x4ee4a30 is 0 bytes inside a block of size 80 alloc'd
==124538== at 0x483CF03: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x7284979: v8::internal::Isolate::Isolate(std::unique_ptr<v8::internal::IsolateAllocator, std::default_delete<v8::internal::IsolateAllocator> >, bool) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x7284CED: v8::internal::Isolate::Allocate(bool) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x673CB24: node::NodeMainInstance::NodeMainInstance(node::SnapshotData const*, uv_loop_s*, node::MultiIsolatePlatform*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x66ABF48: node::Start(int, char**) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x5A42DB1: node_loader_impl_thread(void*) (node_loader_impl.cpp:4189)
==124538== by 0x4842B1A: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x4AA7608: start_thread (pthread_create.c:477)
==124538== by 0x4BE3162: clone (clone.S:95)
==124538== Block was alloc'd by thread #2
==124538==
==124538== Possible data race during write of size 8 at 0x4ED4C40 by thread #7
==124538== Locks held: 1, at address 0x4EE2180
==124538== at 0x729B6A2: v8::internal::StackGuard::RequestInterrupt(v8::internal::StackGuard::InterruptFlag) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x71F8CE7: non-virtual thunk to v8::internal::CancelableTask::Run() (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x676F590: node::(anonymous namespace)::PlatformWorkerThread(void*) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x4842B1A: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x4AA7608: start_thread (pthread_create.c:477)
==124538== by 0x4BE3162: clone (clone.S:95)
==124538==
==124538== This conflicts with a previous read of size 8 by thread #2
==124538== Locks held: 2, at addresses 0x4EC7338 0x4EE4A30
==124538== at 0x6909273: Builtins_InterpreterEntryTrampoline (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0xE012831: ???
==124538== by 0x690928E: Builtins_InterpreterEntryTrampoline (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x690928E: Builtins_InterpreterEntryTrampoline (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x690928E: Builtins_InterpreterEntryTrampoline (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x690928E: Builtins_InterpreterEntryTrampoline (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x690928E: Builtins_InterpreterEntryTrampoline (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x690928E: Builtins_InterpreterEntryTrampoline (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== Address 0x4ed4c40 is 32 bytes inside a block of size 60,536 alloc'd
==124538== at 0x483CF03: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x73D75F9: v8::internal::IsolateAllocator::IsolateAllocator() (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x7284CD6: v8::internal::Isolate::Allocate(bool) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x673CB24: node::NodeMainInstance::NodeMainInstance(node::SnapshotData const*, uv_loop_s*, node::MultiIsolatePlatform*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x66ABF48: node::Start(int, char**) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x5A42DB1: node_loader_impl_thread(void*) (node_loader_impl.cpp:4189)
==124538== by 0x4842B1A: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x4AA7608: start_thread (pthread_create.c:477)
==124538== by 0x4BE3162: clone (clone.S:95)
==124538== Block was alloc'd by thread #2
==124538==
^C==124538==
==124538== Process terminating with default action of signal 2 (SIGINT)
==124538== at 0x4AAE376: futex_wait_cancelable (futex-internal.h:183)
==124538== by 0x4AAE376: __pthread_cond_wait_common (pthread_cond_wait.c:508)
==124538== by 0x4AAE376: pthread_cond_wait@@GLIBC_2.3.2 (pthread_cond_wait.c:638)
==124538== by 0x4842CB3: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124538== by 0x6C51F0C: uv_cond_wait (thread.c:780)
==124538== by 0x5A51ED5: node_loader_impl_try_destroy (node_loader_impl.cpp:5225)
==124538== by 0x5A51ED5: node_loader_impl_try_destroy(loader_impl_node_type*) (node_loader_impl.cpp:5182)
==124538== by 0x5A51F92: node_loader_impl_destroy (node_loader_impl.cpp:5248)
==124538== by 0x487754F: loader_impl_destroy (loader_impl.c:1478)
==124538== by 0x486CCC7: plugin_destroy_delayed (plugin_impl.c:110)
==124538== by 0x4875833: loader_unload_children (loader.c:696)
==124538== by 0x48758D6: loader_destroy (loader.c:742)
==124538== by 0x487B6E0: metacall_destroy (metacall.c:2213)
==124538== by 0x10C20F: metacallcli::application::~application() (application.cpp:197)
==124538== by 0x10BEF0: main (main.cpp:35)
==124538== ----------------------------------------------------------------
==124538==
==124538== Thread #2: Exiting thread still holds 2 locks
==124538== at 0x4BE349E: epoll_wait (epoll_wait.c:30)
==124538== by 0x6C55EEC: uv__io_poll (epoll.c:236)
==124538== by 0x6C43328: uv_run (core.c:389)
==124538== by 0x5A51865: node_loader_impl_destroy_safe_impl (node_loader_impl.cpp:5148)
==124538== by 0x5A51BCD: node_loader_impl_destroy_safe(napi_env__*, loader_impl_async_destroy_safe_type*) [clone .isra.0] (node_loader_impl.cpp:4894)
==124538== by 0x5A51DCE: node_loader_impl_async_destroy_safe(napi_env__*, napi_callback_info__*) (node_loader_impl.cpp:4987)
==124538== by 0x6692315: v8impl::(anonymous namespace)::FunctionCallbackWrapper::Invoke(v8::FunctionCallbackInfo<v8::Value> const&) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x717A5CD: v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x717AF74: v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x717B7DD: v8::internal::Builtins::InvokeApiFunction(v8::internal::Isolate*, bool, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*, v8::internal::Handle<v8::internal::HeapObject>) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x726AB59: v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538== by 0x726B266: v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124538==
==124538==
==124538== Use --history-level=approx or =none to gain increased speed, at
==124538== the cost of reduced accuracy of conflicting-access information
==124538== For lists of detected and suppressed errors, rerun with: -s
==124538== ERROR SUMMARY: 879 errors from 44 contexts (suppressed: 2328 from 310)
and the output from metacall-cli-core-await-test
==124885== Thread #2: Exiting thread still holds 2 locks
==124885== at 0x4AAE376: futex_wait_cancelable (futex-internal.h:183)
==124885== by 0x4AAE376: __pthread_cond_wait_common (pthread_cond_wait.c:508)
==124885== by 0x4AAE376: pthread_cond_wait@@GLIBC_2.3.2 (pthread_cond_wait.c:638)
==124885== by 0x4842CB3: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so)
==124885== by 0x4972E2F: std::condition_variable::wait(std::unique_lock<std::mutex>&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28)
==124885== by 0x16390665: await(unsigned long, void**, void*) (cli_core_plugin.cpp:448)
==124885== by 0x48795AD: metacallfv_s (metacall.c:1025)
==124885== by 0x5A42332: node_loader_impl_napi_to_value_callback(napi_env__*, napi_callback_info__*) (node_loader_impl.cpp:1061)
==124885== by 0x6684315: v8impl::(anonymous namespace)::FunctionCallbackWrapper::Invoke(v8::FunctionCallbackInfo<v8::Value> const&) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124885== by 0x716C5CD: v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124885== by 0x716CF74: v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124885== by 0x716D4AE: v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) (in /home/lord-bryan/opt/lib/libnode.so.108)
==124885== by 0x6978F38: Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit (in /home/lord-bryan/opt/lib/libnode.so.108)
==124885== by 0x68FB28E: Builtins_InterpreterEntryTrampoline (in /home/lord-bryan/opt/lib/libnode.so.108)
==124885==
==124885==
==124885== Use --history-level=approx or =none to gain increased speed, at
==124885== the cost of reduced accuracy of conflicting-access information
==124885== For lists of detected and suppressed errors, rerun with: -s
==124885== ERROR SUMMARY: 35 errors from 22 contexts (suppressed: 5492 from 306)
I haven't been able to reproduce this. Respect to the bug of await, it is due to mixing sync and async calls in the same invokation. My recommendation is clear, avoid executing await from JS in the CLI code, better to implement the basic commands in C/C++.
Basically, the refactor of the CLI has not been done, but the idea is the following, the REPL should do this: 1) Start (C++). 2) Wait for user input (C++ or JS). 3) Parse user input (JS). 4) Return control to C++ with all the parsed information and execute the function of the REPL that has been parsed (C++). 5) Print result and repeat (C++).
In the 4th phase, all the commands related to call, await, load... should be implemented in pure C/C++ (as they are now), so we avoid the deadlock problem with NodeJS. This design solves all problems and makes fully extensible the CLI. Extra extensions (REPL commands or CLI command arguments) can be implemented in pure NodeJS (or any other language if required).
🐛 Bug Report
I hope this is nothing related to set implementation but it can happen. We must intensively test the set implementation to see if it has leaks in some edge case. Also, take into account this:
https://github.com/metacall/core/actions/runs/3191095207/jobs/5206997103