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

Program exits with SIGABRT or SIGSEGV when using libnice #1299

Closed
BlueCannonBall opened this issue Nov 28, 2024 · 3 comments · Fixed by #1300
Closed

Program exits with SIGABRT or SIGSEGV when using libnice #1299

BlueCannonBall opened this issue Nov 28, 2024 · 3 comments · Fixed by #1300

Comments

@BlueCannonBall
Copy link

If a PeerConnection is created anywhere in the program, the program will die by SIGABRT as soon as it exits. This does not happen when using libjuice. See the example below:

#include "rtc/rtc.hpp"

int main() {
	rtc::InitLogger(rtc::LogLevel::Debug);
	auto pc = std::make_shared<rtc::PeerConnection>();
}

Output:

2024-11-28 15:05:08.392 DEBUG [178677] [rtc::impl::Init::doInit@113] Global initialization
2024-11-28 15:05:08.393 DEBUG [178677] [rtc::impl::Init::doInit@123] Spawning 8 threads
2024-11-28 15:05:08.393 DEBUG [178686] [rtc::impl::PollService::runLoop@164] Poll service started
2024-11-28 15:05:08.401 INFO  [178677] [rtc::impl::PeerConnection::changeIceState@1339] Changed ICE state to closed
2024-11-28 15:05:08.401 INFO  [178677] [rtc::impl::PeerConnection::changeState@1321] Changed state to closed
2024-11-28 15:05:08.401 DEBUG [178678] [rtc::impl::Certificate::Generate@445] Generating certificate (OpenSSL)
2024-11-28 15:05:08.401 WARN  [178678] [rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate@105] Unable to generate ECDSA P-256 key pair
terminate called without an active exception
fish: Job 1, './program' terminated by signal SIGABRT (Abort)
@paullouisageneau
Copy link
Owner

paullouisageneau commented Nov 29, 2024

The build looks broken, as the earlier warning "Unable to generate ECDSA P-256 key pair" indicates something is very wrong with OpenSSL. You should try running the program in a debugger, but this is probably not related to libdatachannel itself.

@BlueCannonBall
Copy link
Author

BlueCannonBall commented Nov 29, 2024

The OpenSSL is from apt on Ubuntu 24.10. When I run it with gdb, it either segfaults or throws SIGABRT.

Backtrace when it segfaults:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
2024-11-29 15:11:34.201 DEBUG [208028] [rtc::impl::Init::doInit@113] Global initialization
2024-11-29 15:11:34.201 DEBUG [208028] [rtc::impl::Init::doInit@123] Spawning 8 threads
[New Thread 0x7ffff36006c0 (LWP 208035)]
[New Thread 0x7ffff2c006c0 (LWP 208036)]
[New Thread 0x7ffff22006c0 (LWP 208037)]
[New Thread 0x7ffff18006c0 (LWP 208038)]
[New Thread 0x7ffff0e006c0 (LWP 208039)]
[New Thread 0x7ffff04006c0 (LWP 208040)]
[New Thread 0x7fffefa006c0 (LWP 208041)]
[New Thread 0x7fffef0006c0 (LWP 208042)]
[New Thread 0x7fffee6006c0 (LWP 208043)]
2024-11-29 15:11:34.203 DEBUG [208043] [rtc::impl::PollService::runLoop@164] Poll service started
[New Thread 0x7fffedc006c0 (LWP 208044)]
[New Thread 0x7fffed2006c0 (LWP 208045)]
[New Thread 0x7fffe7e006c0 (LWP 208046)]
2024-11-29 15:11:34.213 DEBUG [208035] [rtc::impl::Certificate::Generate@445] Generating certificate (OpenSSL)
2024-11-29 15:11:34.213 INFO  [208028] [rtc::impl::PeerConnection::changeIceState@1339] Changed ICE state to closed
2024-11-29 15:11:34.213 INFO  [208028] [rtc::impl::PeerConnection::changeState@1321] Changed state to closed
terminate called without an active exception

Thread 2 "RTC worker" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff36006c0 (LWP 208035)]
0x00007ffff6b7a13c in OPENSSL_sk_insert () from /lib/x86_64-linux-gnu/libcrypto.so.3
(gdb) bt
#0  0x00007ffff6b7a13c in OPENSSL_sk_insert () at /lib/x86_64-linux-gnu/libcrypto.so.3
#1  0x00007ffff6b3198c in ??? () at /lib/x86_64-linux-gnu/libcrypto.so.3
#2  0x00007ffff69e8b5a in ??? () at /lib/x86_64-linux-gnu/libcrypto.so.3
#3  0x00007ffff6a4236e in ??? () at /lib/x86_64-linux-gnu/libcrypto.so.3
#4  0x00007ffff6a420b4 in ??? () at /lib/x86_64-linux-gnu/libcrypto.so.3
#5  0x00007ffff6a582f7 in ??? () at /lib/x86_64-linux-gnu/libcrypto.so.3
#6  0x00007ffff6a42213 in ??? () at /lib/x86_64-linux-gnu/libcrypto.so.3
#7  0x00007ffff6a42577 in ??? () at /lib/x86_64-linux-gnu/libcrypto.so.3
#8  0x00007ffff69e8ee2 in ??? () at /lib/x86_64-linux-gnu/libcrypto.so.3
#9  0x00007ffff69e9940 in OSSL_ENCODER_do_all_provided () at /lib/x86_64-linux-gnu/libcrypto.so.3
#10 0x00007ffff69ea324 in OSSL_ENCODER_CTX_new_for_pkey () at /lib/x86_64-linux-gnu/libcrypto.so.3
#11 0x00007ffff6bbbbcc in X509_PUBKEY_set () at /lib/x86_64-linux-gnu/libcrypto.so.3
#12 0x00007ffff6bacd0e in X509_set_pubkey () at /lib/x86_64-linux-gnu/libcrypto.so.3
#13 0x00007ffff7bc5ba2 in rtc::impl::Certificate::Generate (type=rtc::CertificateType::Default, commonName="libdatachannel")
    at /home/optimal/Desktop/mm_files/cpp/libdatachannel-test/src/impl/certificate.cpp:513
#14 0x00007ffff7bc6823 in operator() (__closure=0x5555555b0698)
    at /home/optimal/Desktop/mm_files/cpp/libdatachannel-test/src/impl/certificate.cpp:594
#15 0x00007ffff7bc75a1 in std::__invoke_impl<std::shared_ptr<rtc::impl::Certificate>, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&>(std::__invoke_other, struct {...} &) (__f=...) at /usr/include/c++/14/bits/invoke.h:61
#16 0x00007ffff7bc7361 in std::__invoke<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&>(struct {...} &) (__fn=...)
    at /usr/include/c++/14/bits/invoke.h:97
#17 0x00007ffff7bc71bc in std::_Bind<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>()>::__call<std::shared_ptr<rtc::impl::Certificate> >(std::tuple<> &&, std::_Index_tuple<>) (this=0x5555555b0698, __args=...) at /usr/include/c++/14/functional:515
#18 0x00007ffff7bc702d in std::_Bind<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>()>::operator()<>(void) (this=0x5555555b0698)
    at /usr/include/c++/14/functional:600
#19 0x00007ffff7bc6bb0 in operator() (__closure=0x5555555b0698)
    at /home/optimal/Desktop/mm_files/cpp/libdatachannel-test/src/impl/threadpool.hpp:103
#20 0x00007ffff7bc8d16 in std::__invoke_impl<std::shared_ptr<rtc::impl::Certificate>, rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lam--Type <RET> for more, q to quit, c to continue without paging--c
bda()>&>(std::__invoke_other, struct {...} &) (__f=...) at /usr/include/c++/14/bits/invoke.h:61
#21 0x00007ffff7bc8af3 in std::__invoke_r<std::shared_ptr<rtc::impl::Certificate>, rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()>&>(struct {...} &) (__fn=...) at /usr/include/c++/14/bits/invoke.h:116
#22 0x00007ffff7bc87e9 in operator() (__closure=0x7ffff35fd0b8) at /usr/include/c++/14/future:1499
#23 0x00007ffff7bc94dd in std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<std::shared_ptr<rtc::impl::Certificate> >, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_state<rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()>, std::allocator<int>, std::shared_ptr<rtc::impl::Certificate>()>::_M_run()::<lambda()>, std::shared_ptr<rtc::impl::Certificate> >::operator()(void) const (this=0x7ffff35fd0d0) at /usr/include/c++/14/future:1416
#24 0x00007ffff7bc9353 in std::__invoke_impl<std::unique_ptr<std::__future_base::_Result<std::shared_ptr<rtc::impl::Certificate> >, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<std::shared_ptr<rtc::impl::Certificate> >, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_state<rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()>, std::allocator<int>, std::shared_ptr<rtc::impl::Certificate>()>::_M_run()::<lambda()>, std::shared_ptr<rtc::impl::Certificate> >&>(std::__invoke_other, std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<std::shared_ptr<rtc::impl::Certificate> >, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_state<rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()>, std::allocator<int>, std::shared_ptr<rtc::impl::Certificate>()>::_M_run()::<lambda()>, std::shared_ptr<rtc::impl::Certificate> > &) (__f=...)
    at /usr/include/c++/14/bits/invoke.h:61
#25 0x00007ffff7bc9035 in std::__invoke_r<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<std::shared_ptr<rtc::impl::Certificate> >, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_state<rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()>, std::allocator<int>, std::shared_ptr<rtc::impl::Certificate>()>::_M_run()::<lambda()>, std::shared_ptr<rtc::impl::Certificate> >&>(std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<std::shared_ptr<rtc::impl::Certificate> >, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_state<rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()>, std::allocator<int>, std::shared_ptr<rtc::impl::Certificate>()>::_M_run()::<lambda()>, std::shared_ptr<rtc::impl::Certificate> > &) (__fn=...) at /usr/include/c++/14/bits/invoke.h:114
#26 0x00007ffff7bc8dbf in std::_Function_handler<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>(), std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<std::shared_ptr<rtc::impl::Certificate> >, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_state<rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()>, std::allocator<int>, std::shared_ptr<rtc::impl::Certificate>()>::_M_run()::<lambda()>, std::shared_ptr<rtc::impl::Certificate> > >::_M_invoke(const std::_Any_data &)
    (__functor=...) at /usr/include/c++/14/bits/std_function.h:291
#27 0x00007ffff7bbee60 in std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()>::operator() (this=0x7ffff35fd0d0) at /usr/include/c++/14/bits/std_function.h:591
#28 0x00007ffff7bbe4c2 in std::__future_base::_State_baseV2::_M_do_set (this=0x5555555b0670, __f=0x7ffff35fd0d0, __did_set=0x7ffff35fd01f)
    at /usr/include/c++/14/future:596
#29 0x00007ffff7bc028d in std::__invoke_impl<void, void (std::__future_base::_State_baseV2::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()>*, bool*), std::__future_base::_State_baseV2*, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()>*, bool*>
    (__f=@0x7ffff35fd060: (void (std::__future_base::_State_baseV2::*)(std::__future_base::_State_baseV2 * const, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()> *, bool *)) 0x7ffff7bbe488 <std::__future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*)>, __t=@0x7ffff35fd030: 0x5555555b0670) at /usr/include/c++/14/bits/invoke.h:74
#30 0x00007ffff7bbf767 in std::__invoke<void (std::__future_base::_State_baseV2::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()>*, bool*), std::__future_base::_State_baseV2*, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()>*, bool*>
    (__fn=@0x7ffff35fd060: (void (std::__future_base::_State_baseV2::*)(std::__future_base::_State_baseV2 * const, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()> *, bool *)) 0x7ffff7bbe488 <std::__future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*)>)
    at /usr/include/c++/14/bits/invoke.h:96
#31 0x00007ffff7bbea08 in std::call_once<void (std::__future_base::_State_baseV2::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*), std::__future_base::_State_baseV2*, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*>(std::once_flag&, void (std::__future_base::_State_baseV2::*&&)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*), std::__future_base::_State_baseV2*&&, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*&&, bool*&&)::{lambda()#1}::operator()() const (__closure=0x7ffff35fcfa0) at /usr/include/c++/14/mutex:909
#32 0x00007ffff7bbf79f in std::once_flag::_Prepare_execution::_Prepare_execution<std::call_once<void (std::__future_base::_State_baseV2::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*), std::__future_base::_State_baseV2*, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*>(std::once_flag&, void (std::__future_base::_State_baseV2::*&&)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*), std::__future_base::_State_baseV2*&&, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*&&, bool*&&)::{lambda()#1}>(void (std::__future_base::_State_baseV2::*&)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*))::{lambda()#1}::operator()() const (__closure=0x0) at /usr/include/c++/14/mutex:845
#33 0x00007ffff7bbf7b4 in std::once_flag::_Prepare_execution::_Prepare_execution<std::call_once<void (std::__future_base::_State_baseV2::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*), std::__future_base::_State_baseV2*, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*>(std::once_flag&, void (std::__future_base::_State_baseV2::*&&)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*), std::__future_base::_State_baseV2*&&, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*&&, bool*&&)::{lambda()#1}>(void (std::__future_base::_State_baseV2::*&)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*))::{lambda()#1}::_FUN() () at /usr/include/c++/14/mutex:845
#34 0x00007ffff6ea73cb in __pthread_once_slow (once_control=0x5555555b0688, init_routine=0x7ffff72eb420 <__once_proxy>)
    at ./nptl/pthread_once.c:116
#35 0x00007ffff6ea7439 in ___pthread_once (once_control=<optimized out>, init_routine=<optimized out>) at ./nptl/pthread_once.c:143
#36 0x00007ffff7bbd908 in __gthread_once (__once=0x5555555b0688, __func=0x7ffff72eb420 <__once_proxy>)
    at /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:713
#37 0x00007ffff7bbea8d in std::call_once<void (std::__future_base::_State_baseV2::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()>*, bool*), std::__future_base::_State_baseV2*, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()>*, bool*>
    (__once=..., __f=@0x7ffff35fd060: (void (std::__future_base::_State_baseV2::*)(std::__future_base::_State_baseV2 * const, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()> *, bool *)) 0x7ffff7bbe488 <std::__future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*)>)
    at /usr/include/c++/14/mutex:916
#38 0x00007ffff7bbe03a in std::__future_base::_State_baseV2::_M_set_result (this=0x5555555b0670, __res=..., __ignore_failure=false)
    at /usr/include/c++/14/future:435
#39 0x00007ffff7bc8876 in std::__future_base::_Task_state<rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()>, std::allocator<int>, std::shared_ptr<rtc::impl::Certificate>()>::_M_run(void) (this=0x5555555b0670) at /usr/include/c++/14/future:1501
#40 0x00007ffff7bcbc35 in std::packaged_task<std::shared_ptr<rtc::impl::Certificate>()>::operator() (this=0x5555555e8e00)
    at /usr/include/c++/14/future:1635
#41 0x00007ffff7bc6ddc in operator() (__closure=0x7fffd8000b70)
    at /home/optimal/Desktop/mm_files/cpp/libdatachannel-test/src/impl/threadpool.hpp:111
#42 0x00007ffff7bc7770 in std::__invoke_impl<void, rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()>&>(std::__invoke_other, struct {...} &) (__f=...) at /usr/include/c++/14/bits/invoke.h:61
#43 0x00007ffff7bc7492 in std::__invoke_r<void, rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()>&>(struct {...} &) (__fn=...)
    at /usr/include/c++/14/bits/invoke.h:111
#44 0x00007ffff7bc7294 in std::_Function_handler<void(), rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate(rtc::CertificateType)::<lambda()> >(std::chrono::_V2::steady_clock::time_point, rtc::impl::make_certificate(rtc::CertificateType)::<lambda()>&&)::<lambda()> >::_M_invoke(const std::_Any_data &) (__functor=...) at /usr/include/c++/14/bits/std_function.h:290
#45 0x00007ffff7ad1aee in std::function<void()>::operator() (this=0x7ffff35fd1f0) at /usr/include/c++/14/bits/std_function.h:591
#46 0x00007ffff7c6659f in rtc::impl::ThreadPool::runOne (this=0x55555559a8b0)
    at /home/optimal/Desktop/mm_files/cpp/libdatachannel-test/src/impl/threadpool.cpp:67
#47 0x00007ffff7c664a4 in rtc::impl::ThreadPool::run (this=0x55555559a8b0)
    at /home/optimal/Desktop/mm_files/cpp/libdatachannel-test/src/impl/threadpool.cpp:61
#48 0x00007ffff7c69c73 in std::__invoke_impl<void, void (rtc::impl::ThreadPool::*&)(), rtc::impl::ThreadPool*&>
    (__f=@0x55555559a818: (void (rtc::impl::ThreadPool::*)(rtc::impl::ThreadPool * const)) 0x7ffff7c663e4 <rtc::impl::ThreadPool::run()>, __t=@0x55555559a828: 0x55555559a8b0) at /usr/include/c++/14/bits/invoke.h:74
#49 0x00007ffff7c69bef in std::__invoke<void (rtc::impl::ThreadPool::*&)(), rtc::impl::ThreadPool*&>
    (__fn=@0x55555559a818: (void (rtc::impl::ThreadPool::*)(rtc::impl::ThreadPool * const)) 0x7ffff7c663e4 <rtc::impl::ThreadPool::run()>)
    at /usr/include/c++/14/bits/invoke.h:96
#50 0x00007ffff7c69b59 in std::_Bind<void (rtc::impl::ThreadPool::*(rtc::impl::ThreadPool*))()>::__call<void, , 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>) (this=0x55555559a818, __args=...) at /usr/include/c++/14/functional:513
#51 0x00007ffff7c69ad5 in std::_Bind<void (rtc::impl::ThreadPool::*(rtc::impl::ThreadPool*))()>::operator()<, void>() (this=0x55555559a818)
    at /usr/include/c++/14/functional:598
#52 0x00007ffff7c69a7c in std::__invoke_impl<void, std::_Bind<void (rtc::impl::ThreadPool::*(rtc::impl::ThreadPool*))()>>(std::__invoke_other, std::_Bind<void (rtc::impl::ThreadPool::*(rtc::impl::ThreadPool*))()>&&) (__f=...) at /usr/include/c++/14/bits/invoke.h:61
#53 0x00007ffff7c69a37 in std::__invoke<std::_Bind<void (rtc::impl::ThreadPool::*(rtc::impl::ThreadPool*))()>>(std::_Bind<void (rtc::impl::ThreadPool::*(rtc::impl::ThreadPool*))()>&&) (__fn=...) at /usr/include/c++/14/bits/invoke.h:96
#54 0x00007ffff7c699d8 in std::thread::_Invoker<std::tuple<std::_Bind<void (rtc::impl::ThreadPool::*(rtc::impl::ThreadPool*))()> > >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (this=0x55555559a818) at /usr/include/c++/14/bits/std_thread.h:301
#55 0x00007ffff7c699a8 in std::thread::_Invoker<std::tuple<std::_Bind<void (rtc::impl::ThreadPool::*(rtc::impl::ThreadPool*))()> > >::operator()()
    (this=0x55555559a818) at /usr/include/c++/14/bits/std_thread.h:308
#56 0x00007ffff7c69988 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<std::_Bind<void (rtc::impl::ThreadPool::*(rtc::impl::ThreadPool*))()> > > >::_M_run() (this=0x55555559a810) at /usr/include/c++/14/bits/std_thread.h:253
#57 0x00007ffff72ecdb4 in ??? () at /lib/x86_64-linux-gnu/libstdc++.so.6
#58 0x00007ffff6ea1e2e in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:447
#59 0x00007ffff6f33a4c in __GI___clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

Backtrace when it throws SIGABRT:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
2024-11-29 15:14:48.320 DEBUG [208457] [rtc::impl::Init::doInit@113] Global initialization
2024-11-29 15:14:48.320 DEBUG [208457] [rtc::impl::Init::doInit@123] Spawning 8 threads
[New Thread 0x7ffff36006c0 (LWP 208462)]
[New Thread 0x7ffff2c006c0 (LWP 208463)]
[New Thread 0x7ffff22006c0 (LWP 208464)]
[New Thread 0x7ffff18006c0 (LWP 208465)]
[New Thread 0x7ffff0e006c0 (LWP 208466)]
[New Thread 0x7ffff04006c0 (LWP 208467)]
[New Thread 0x7fffefa006c0 (LWP 208468)]
[New Thread 0x7fffef0006c0 (LWP 208469)]
[New Thread 0x7fffee6006c0 (LWP 208470)]
2024-11-29 15:14:48.323 DEBUG [208470] [rtc::impl::PollService::runLoop@164] Poll service started
[New Thread 0x7fffedc006c0 (LWP 208471)]
[New Thread 0x7fffed2006c0 (LWP 208472)]
[New Thread 0x7fffe7e006c0 (LWP 208473)]
2024-11-29 15:14:48.329 DEBUG [208462] [rtc::impl::Certificate::Generate@445] Generating certificate (OpenSSL)
2024-11-29 15:14:48.330 INFO  [208457] [rtc::impl::PeerConnection::changeIceState@1339] Changed ICE state to closed
2024-11-29 15:14:48.330 INFO  [208457] [rtc::impl::PeerConnection::changeState@1321] Changed state to closed
2024-11-29 15:14:48.330 WARN  [208462] [rtc::impl::ThreadPool::schedule<rtc::impl::make_certificate@105] Unable to generate ECDSA P-256 key pair
terminate called without an active exception

Thread 1 "media-sender" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=<optimized out>, signo=6, no_tid=0) at ./nptl/pthread_kill.c:44
warning: 44     ./nptl/pthread_kill.c: No such file or directory
(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=6, no_tid=0) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (threadid=<optimized out>, signo=6) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff6e4519e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff6e28902 in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007ffff72a5ff5 in ??? () at /lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff72bb0da in ??? () at /lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00007ffff72a5a55 in std::terminate() () at /lib/x86_64-linux-gnu/libstdc++.so.6
#8  0x00007ffff7bed16d in std::__terminate () at /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:324
#9  std::thread::~thread (this=0x7ffff7eaabf0 <rtc::impl::IceTransport::MainLoopThread>, __in_chrg=<optimized out>)
    at /usr/include/c++/14/bits/std_thread.h:182
#10 0x00007ffff6e47482 in __cxa_finalize (d=0x7ffff7ea8ee0) at ./stdlib/cxa_finalize.c:97
#11 0x00007ffff7ac5d17 in __do_global_dtors_aux () at /home/optimal/Desktop/mm_files/cpp/libdatachannel-test/build/libdatachannel.so.0.22
#12 0x00007fffffffdd70 in ??? ()
#13 0x00007ffff7fc40f2 in _dl_call_fini (closure_map=0x7ffff7fbb2b0) at ./elf/dl-call_fini.c:43

EDIT: It also segfaults sometimes when I run it without gdb.

@BlueCannonBall BlueCannonBall changed the title Program exits with SIGABRT when using libnice Program exits with SIGABRT or SIGSEGV when using libnice Nov 29, 2024
@paullouisageneau
Copy link
Owner

OK, this is unrelated to libnice and actually a problem with OpenSSL. The issue is that your test program creates a peer connection then immediately exits. It appears OpenSSL registers an atexit handler to cleanup everything as soon as the main thread exits. In this case, the certificate is created in a background thread during cleanup so it leads to a race condition in OpenSSL.

The issue will disappear if the program does not exit immediately, however it could happen in other scenarios at exit so I pushed a fix in #1300.

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

Successfully merging a pull request may close this issue.

2 participants