Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples/tls.js segfaults on docker container and virtual machine #105

Open
MayamaTakeshi opened this issue Jun 7, 2024 · 3 comments
Open

Comments

@MayamaTakeshi
Copy link
Owner

MayamaTakeshi commented Jun 7, 2024

It doesn't happen with my ubuntu desktop 22.04.
But on Debian 11 container or VM i get (100% reproducible):

05:01:45.615  [
  partial_match({
    event: 'incoming_call',
    call_id: collect['call_id'](),
    transport_id: 1
  }),
  partial_match({
    event: 'response',
    call_id: 0,
    method: 'INVITE',
    msg: sip_msg({
      $rs: '100',
      $rr: 'Trying'
    })
  })
]
DEBUG: 05:01:45.617        ssl_sock_ossl.c  OpenSSL version : 269488511
DEBUG: 05:01:45.618           ssl0x793bce0  Certificate chain loaded from 'samples/artifacts/tls/cacert.pem'
DEBUG: 05:01:45.619           ssl0x793bce0  Private key loaded from 'samples/artifacts/tls/cakey.pem'
ERROR: 05:01:45.619           ssl0x793bce0  Error reading CA certificates from buffer
DEBUG: 05:01:45.619           ssl0x799ac10  Certificate chain loaded from 'samples/artifacts/tls/cacert.pem'
DEBUG: 05:01:45.620           ssl0x799ac10  Private key loaded from 'samples/artifacts/tls/cakey.pem'
TRACE: 05:01:45.769        ssl_sock_ossl.c  Session info: reused=0, resumable=1, timeout=300
TRACE: 05:01:45.769        ssl_sock_ossl.c  Session id: 96C4215CC20D054C811F73E343FE121400BBF56318E6F2D48A8BE9A2259F2499
TRACE: 05:01:45.769        ssl_sock_ossl.c  Session id context: 2300

Thread 1 "node" received signal SIGSEGV, Segmentation fault.
0x000070a76923a2a3 in SSL_get_peer_certificate () from /usr/lib/x86_64-linux-gnu/libssl.so.1.1
(gdb) bt
#0  0x000070a76923a2a3 in SSL_get_peer_certificate () from /usr/lib/x86_64-linux-gnu/libssl.so.1.1
#1  0x000070a7693bf3dc in ?? () from /tmp/t1/node_modules/sip-lab/prebuilds/linux-x64/sip-lab.node
#2  0x000070a7693c0ef8 in ?? () from /tmp/t1/node_modules/sip-lab/prebuilds/linux-x64/sip-lab.node
#3  0x000070a7693b5d1d in ?? () from /tmp/t1/node_modules/sip-lab/prebuilds/linux-x64/sip-lab.node
#4  0x000070a7693b0618 in ioqueue_dispatch_read_event () from /tmp/t1/node_modules/sip-lab/prebuilds/linux-x64/sip-lab.node
#5  0x000070a7693b21a7 in pj_ioqueue_poll () from /tmp/t1/node_modules/sip-lab/prebuilds/linux-x64/sip-lab.node
#6  0x000070a76937bdea in pjsip_endpt_handle_events2 () from /tmp/t1/node_modules/sip-lab/prebuilds/linux-x64/sip-lab.node
#7  0x000070a76930b954 in handle_events() () from /tmp/t1/node_modules/sip-lab/prebuilds/linux-x64/sip-lab.node
#8  0x000070a76930c720 in __pjw_poll(char*) () from /tmp/t1/node_modules/sip-lab/prebuilds/linux-x64/sip-lab.node
#9  0x000070a769329ce2 in do_poll(Napi::CallbackInfo const&) () from /tmp/t1/node_modules/sip-lab/prebuilds/linux-x64/sip-lab.node
#10 0x000070a769332a2c in Napi::details::CallbackData<Napi::Value (*)(Napi::CallbackInfo const&), Napi::Value>::Wrapper(napi_env__*, napi_callback_info__*) ()
   from /tmp/t1/node_modules/sip-lab/prebuilds/linux-x64/sip-lab.node
#11 0x0000000000d7c3a9 in v8impl::(anonymous namespace)::FunctionCallbackWrapper::Invoke(v8::FunctionCallbackInfo<v8::Value> const&) ()
#12 0x000070a763e0eadd in ?? ()
#13 0x00007fffbed4c620 in ?? ()
#14 0x00007fffbed4c658 in ?? ()
#15 0x0000000000000000 in ?? ()
(gdb) 

So there might be some race condition and a mutex lock missing somewhere.

Node version: v21.2.0

@MayamaTakeshi
Copy link
Owner Author

Obs: the 'Error reading CA certificates from buffer' always happens even when there is no segfault and the test succeeds.
(it might be related though).

@MayamaTakeshi
Copy link
Owner Author

In the Debian 11 VM I built sip-lab from source using v16.20.2 and with this tls.js didn't segfault.
Then i switched to node v21.6.1 and then tls.js segfaulted.
So i tried to rebuild the addon with v21.6.1 but got:


$ npm run rebuild
... ABRIDGED ...
In file included from /root/tmp/MayamaTakeshi/sip-lab/node_modules/node-addon-api/napi.h:3112,
                 from ../src/addon.cpp:4:
/root/tmp/MayamaTakeshi/sip-lab/node_modules/node-addon-api/napi-inl.h: In instantiation of ‘napi_status Napi::details::AttachData(napi_env, napi_value, FreeType*, napi_finalize, void*) [with FreeType = Napi::details::CallbackData<Napi::Value (*)(const Napi::CallbackInfo&), Napi::Value>; napi_env = napi_env__*; napi_value = napi_value__*; napi_finalize = void (*)(napi_env__*, void*, void*)]’:
/root/tmp/MayamaTakeshi/sip-lab/node_modules/node-addon-api/napi-inl.h:2188:39:   required from ‘napi_status Napi::CreateFunction(napi_env, const char*, napi_callback, CbData*, napi_value__**) [with CbData = Napi::details::CallbackData<Napi::Value (*)(const Napi::CallbackInfo&), Napi::Value>; napi_env = napi_env__*; napi_callback = napi_value__* (*)(napi_env__*, napi_callback_info__*); napi_value = napi_value__*; napi_callback_info = napi_callback_info__*]’
/root/tmp/MayamaTakeshi/sip-lab/node_modules/node-addon-api/napi-inl.h:2245:21:   required from ‘static Napi::Function Napi::Function::New(napi_env, Callable, const char*, void*) [with Callable = Napi::Value (*)(const Napi::CallbackInfo&); napi_env = napi_env__*]’
../src/addon.cpp:1382:54:   required from here
/root/tmp/MayamaTakeshi/sip-lab/node_modules/node-addon-api/napi-inl.h:62:47: error: invalid conversion from ‘napi_finalize’ {aka ‘void (*)(napi_env__*, void*, void*)’} to ‘node_api_nogc_finalize’ {aka ‘void (*)(const napi_env__*, void*, void*)’} [-fpermissive]
   62 |   status = napi_add_finalizer(env, obj, data, finalizer, hint, nullptr);
      |                                               ^~~~~~~~~
      |                                               |
      |                                               napi_finalize {aka void (*)(napi_env__*, void*, void*)}
In file included from /root/.cache/node-gyp/21.6.1/include/node/node_api.h:12,
                 from /root/tmp/MayamaTakeshi/sip-lab/node_modules/node-addon-api/napi.h:4,
                 from ../src/addon.cpp:4:
/root/.cache/node-gyp/21.6.1/include/node/js_native_api.h:516:43: note:   initializing argument 4 of ‘napi_status napi_add_finalizer(napi_env, napi_value, void*, node_api_nogc_finalize, void*, napi_ref__**)’
  516 |                    node_api_nogc_finalize finalize_cb,
      |                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
make: *** [addon.target.mk:185: Release/obj.target/addon/src/addon.o] Error 1
make: Leaving directory '/root/tmp/MayamaTakeshi/sip-lab/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/root/tmp/MayamaTakeshi/sip-lab/node_modules/node-gyp/lib/build.js:203:23)
gyp ERR! stack     at ChildProcess.emit (node:events:519:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:294:12)
gyp ERR! System Linux 5.10.0-27-amd64
gyp ERR! command "/root/.nvm/versions/node/v21.6.1/bin/node" "/root/tmp/MayamaTakeshi/sip-lab/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd /root/tmp/MayamaTakeshi/sip-lab
gyp ERR! node -v v21.6.1
gyp ERR! node-gyp -v v9.3.0
gyp ERR! not ok 

And indeed, if I do 'npm i sip-lab' and use node v16, there is no problem.

So prebuildify is not working (not generating addon for different node versions)

MayamaTakeshi added a commit that referenced this issue Jun 8, 2024
@MayamaTakeshi
Copy link
Owner Author

The problem is explained in prebuild/prebuildify/issues 90.
For now we will stay with [email protected].
Doing:

nvm use v16.13.1
npx prebuildify-cross -i mayamatakeshi/sip-lab-debian11:latest -t 15.0.0 -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 -t 21.0.0 --strip

we got:

takeshi@takeshi-desktop:sip-lab$ tree prebuilds
prebuilds
└── linux-x64
    ├── node.abi102.node
    ├── node.abi108.node
    ├── node.abi111.node
    ├── node.abi115.node
    ├── node.abi120.node
    ├── node.abi88.node
    └── node.abi93.node

However, after installing [email protected], on vm 225.11, I got:

  • v15 : OK
  • v16: OK
  • v17: segfault
  • v18: segfault
  • v19: segfault
  • v20: segfault
  • v21: segfault

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant