Koromix / koffi

Fast and easy-to-use C FFI module for Node.js
https://koffi.dev/
MIT License
189 stars 3 forks source link

Random crash using koffi in node:worker_thread #190

Open nomagick opened 1 month ago

nomagick commented 1 month ago

Koffi version: 2.9.0 Node version: 20.16.0

I encounter seemingly random crashes while using koffi in node:worker_thread. It does not crash most of the time, but crashes could be found in the logs.

Both node main thread and the worker thread load the same lib(libmagic) using koffi. https://www.npmjs.com/package/libmagic-ffi?activeTab=code

Seems random; the probability is roughly 1% - 5%

INFO 2024-09-10T03:58:15.916631Z Default STARTUP TCP probe succeeded after 1 attempt for container "worker" on port 8080.
DEFAULT 2024-09-10T03:59:11.093376Z FATAL ERROR: Error::ThrowAsJavaScriptException napi_throw
DEFAULT 2024-09-10T03:59:11.093437Z ----- Native stack trace -----
DEFAULT 2024-09-10T03:59:11.093455Z 1: 0x55919c5714fb node::OnFatalError(char const*, char const*) [node]
DEFAULT 2024-09-10T03:59:11.093904Z 2: 0x55919c680732 napi_fatal_error [node]
DEFAULT 2024-09-10T03:59:11.094033Z 3: 0x7f2948427aa7 [/workspace/node_modules/koffi/build/koffi/linux_x64/koffi.node]
DEFAULT 2024-09-10T03:59:11.094231Z 4: 0x7f294842b979 [/workspace/node_modules/koffi/build/koffi/linux_x64/koffi.node]
DEFAULT 2024-09-10T03:59:11.094665Z 5: 0x7f29483ecd55 RG::AsyncCall::OnOK() [/workspace/node_modules/koffi/build/koffi/linux_x64/koffi.node]
DEFAULT 2024-09-10T03:59:11.094677Z 6: 0x7f294842de73 Napi::AsyncWorker::OnWorkComplete(Napi::Env, napi_status) [/workspace/node_modules/koffi/build/koffi/linux_x64/koffi.node]
DEFAULT 2024-09-10T03:59:11.095659Z 7: 0x55919c6841a8 node::ThreadPoolWork::ScheduleWork()::{lambda(uv_work_s*, int)#2}::_FUN(uv_work_s*, int) [node]
DEFAULT 2024-09-10T03:59:11.096810Z 8: 0x55919d3683b9 [node]
DEFAULT 2024-09-10T03:59:11.098983Z 9: 0x55919d36c793 [node]
DEFAULT 2024-09-10T03:59:11.099616Z 10: 0x55919d382d93 [node]
DEFAULT 2024-09-10T03:59:11.101273Z 11: 0x55919d36d607 uv_run [node]
DEFAULT 2024-09-10T03:59:11.102175Z 12: 0x55919c6302b1 node::Environment::CleanupHandles() [node]
DEFAULT 2024-09-10T03:59:11.103005Z 13: 0x55919c630368 node::Environment::RunCleanup() [node]
DEFAULT 2024-09-10T03:59:11.104030Z 14: 0x55919c5cbdf7 node::FreeEnvironment(node::Environment*) [node]
DEFAULT 2024-09-10T03:59:11.104732Z 15: 0x55919c7d7407 node::worker::Worker::Run() [node]
DEFAULT 2024-09-10T03:59:11.105593Z 16: 0x55919c7d781c [node]
DEFAULT 2024-09-10T03:59:11.105607Z 17: 0x7f294a73eac3 [/lib/x86_64-linux-gnu/libc.so.6]
DEFAULT 2024-09-10T03:59:11.105696Z 18: 0x7f294a7d0850 [/lib/x86_64-linux-gnu/libc.so.6]
WARNING 2024-09-10T03:59:11.140943Z Container terminated on signal 11.
Koromix commented 1 month ago

I'd like to look into this soon. Do you have a complete or code base and a way for me to test and reproduce this easily?

nomagick commented 1 month ago

This was inside Google Firebase Functions v2, on Google Cloud Run.

I'll try to reproduce and create a separate repo then.