Blocking I/O on main thread
We see in the first backtrace below that it's possible for the MultiplexedSocket::write
function to be called from the main thread, even though it's a potentially blocking operation. (In my case, the main thread was blocked because MultiplexedSocket::write
was waiting to acquire a mutex that was held by a different thread due to another call to MultiplexedSocket::write
that couldn't return due to being stuck on IceTransport::send
a few layers down the stack.)
#0 futex_wait (private=0, expected=2, futex_word=0x72409ba7bf28) at ../sysdeps/nptl/futex-internal.h:146
#1 __GI___lll_lock_wait (futex=futex@entry=0x72409ba7bf28, private=0) at ./nptl/lowlevellock.c:49
#2 0x00007240eb0a00f1 in lll_mutex_lock_optimized (mutex=0x72409ba7bf28) at ./nptl/pthread_mutex_lock.c:48
#3 ___pthread_mutex_lock (mutex=0x72409ba7bf28) at ./nptl/pthread_mutex_lock.c:93
#4 0x00007240ec3b7403 in dhtnet::MultiplexedSocket::write(unsigned short const&, unsigned char const*, unsigned long, std::error_code&) () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#5 0x00007240ec3b7e8a in dhtnet::ChannelSocket::write(unsigned char const*, unsigned long, std::error_code&) () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#6 0x00007240ec0e1be6 in jami::MessageChannelHandler::sendMessage (socket=warning: RTTI symbol not found for class 'std::_Sp_counted_ptr_inplace<dhtnet::ChannelSocket, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>'
warning: RTTI symbol not found for class 'std::_Sp_counted_ptr_inplace<dhtnet::ChannelSocket, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>'
std::shared_ptr<dhtnet::ChannelSocket> (use count 4, weak count 1) = {...}, message=...) at jamidht/message_channel_handler.cpp:180
#7 0x00007240ebea3459 in jami::JamiAccount::sendMessage
(this=0x724048000db0, to="9d04a65284271ac3be1ddac9e3d43607d7df9527", deviceId="", payloads=std::map with 1 element = {...}, token=6990070323537786, retryOnTimeout=false, onlyConnected=true) at jamidht/jamiaccount.cpp:3068
#8 0x00007240ebea6eb6 in jami::JamiAccount::sendInstantMessage (this=0x724048000db0, convId="e226201a16e9fe5a1ff757f92b7288cdb11727eb", msg=std::map with 1 element = {...}) at jamidht/jamiaccount.cpp:3515
#9 0x00007240ebea053c in jami::JamiAccount::setMessageDisplayed (this=0x724048000db0, conversationUri="swarm:e226201a16e9fe5a1ff757f92b7288cdb11727eb", messageId="3d1f18cc46bcfbaf1fa9b1b927c3f0b0d058700d", status=3)
at jamidht/jamiaccount.cpp:2799
#10 0x00007240ebe307c4 in libjami::setMessageDisplayed (accountId="8117603b74c4e2fb", conversationUri="swarm:e226201a16e9fe5a1ff757f92b7288cdb11727eb", messageId="3d1f18cc46bcfbaf1fa9b1b927c3f0b0d058700d", status=3)
at client/configurationmanager.cpp:336
#11 0x00005f1dc746b69a in ConfigurationManagerInterface::setMessageDisplayed (this=<optimized out>, status=3, messageId=..., contactId=..., accountId=<optimized out>)
at /home/ffauteux-chapleau/jami-client-qt/src/libclient/dbus/../qtwrapper/configurationmanager_wrap.h:978
#12 lrc::api::ConversationModel::clearUnreadInteractions (this=0x5f1ddfaf6f00, convId=...) at /home/ffauteux-chapleau/jami-client-qt/src/libclient/conversationmodel.cpp:1568
#13 0x00005f1dc72f23e7 in MessagesAdapter::onNewInteraction (this=0x5f1de1427af0, convUid=..., interactionId=..., interaction=...) at /home/ffauteux-chapleau/jami-client-qt/src/app/messagesadapter.cpp:403
#14 0x00005f1dc72f6ff0 in QtPrivate::FunctorCall<QtPrivate::IndexesList<0, 1, 2>, QtPrivate::List<QString const&, QString&, lrc::api::interaction::Info const&>, void, void (MessagesAdapter::*)(QString const&, QString const&, lrc::api::interaction::Info const&)>::call
(f=(void (MessagesAdapter::*)(class MessagesAdapter * const, const class QString &, const class QString &, const struct lrc::api::interaction::Info &)) 0x5f1dc72f232a <MessagesAdapter::onNewInteraction(QString const&, QString const&, lrc::api::interaction::Info const&)>, o=0x5f1de1427af0, arg=0x7ffe044e1830) at /usr/lib/libqt-jami/include/QtCore/qobjectdefs_impl.h:145
#15 0x00005f1dc72f7037 in QtPrivate::FunctionPointer<void (MessagesAdapter::*)(QString const&, QString const&, lrc::api::interaction::Info const&)>::call<QtPrivate::List<QString const&, QString&, lrc::api::interaction::Info const&>, void> (arg=<optimized out>, o=<optimized out>, f=<optimized out>) at /usr/lib/libqt-jami/include/QtCore/qobjectdefs_impl.h:182
#16 QtPrivate::QCallableObject<void (MessagesAdapter::*)(QString const&, QString const&, lrc::api::interaction::Info const&), QtPrivate::List<QString const&, QString&, lrc::api::interaction::Info const&>, void>::impl
(which=<optimized out>, this_=<optimized out>, r=<optimized out>, a=<optimized out>, ret=<optimized out>) at /usr/lib/libqt-jami/include/QtCore/qobjectdefs_impl.h:520
#17 0x00007240f06e78b3 in ??? () at /usr/lib/libqt-jami/lib/libQt6Core.so.6
#18 0x00005f1dc7457800 in lrc::api::ConversationModel::newInteraction (this=<optimized out>, _t1=..., _t2=..., _t3=...)
at /home/ffauteux-chapleau/jami-client-qt/build/src/libclient/jamiclient_autogen/include/api/moc_conversationmodel.cpp:712
#19 0x00005f1dc7468171 in lrc::ConversationModelPimpl::slotMessageReceived (this=0x5f1ddfc66310, accountId=<optimized out>, conversationId=..., message=...)
at /home/ffauteux-chapleau/jami-client-qt/src/libclient/conversationmodel.cpp:2396
#20 0x00007240f06e78b3 in ??? () at /usr/lib/libqt-jami/lib/libQt6Core.so.6
#21 0x00005f1dc73fd133 in lrc::CallbacksHandler::messageReceived (this=<optimized out>, _t1=<optimized out>, _t2=<optimized out>, _t3=<optimized out>)
at /home/ffauteux-chapleau/jami-client-qt/build/src/libclient/jamiclient_autogen/EWIEGA46WW/moc_callbackshandler.cpp:2494
#22 0x00007240f06e633e in QObject::event(QEvent*) () at /usr/lib/libqt-jami/lib/libQt6Core.so.6
#23 0x00007240ef0c6155 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/libqt-jami/lib/libQt6Widgets.so.6
#24 0x00007240f06e9eb8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/libqt-jami/lib/libQt6Core.so.6
#25 0x00007240f06ea217 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () at /usr/lib/libqt-jami/lib/libQt6Core.so.6
#26 0x00007240f07e67d7 in ??? () at /usr/lib/libqt-jami/lib/libQt6Core.so.6
#27 0x00007240f146a5b5 in ??? () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#28 0x00007240f14c9717 in ??? () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#29 0x00007240f1469a53 in g_main_context_iteration () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#30 0x00007240f0780dd0 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libqt-jami/lib/libQt6Core.so.6
#31 0x00007240f06e3fab in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libqt-jami/lib/libQt6Core.so.6
#32 0x00007240f07e6b4a in QCoreApplication::exec() () at /usr/lib/libqt-jami/lib/libQt6Core.so.6
#33 0x00005f1dc72d19ee in main (argc=<optimized out>, argv=0x7ffe044e2278) at /home/ffauteux-chapleau/jami-client-qt/src/app/main.cpp:145
(gdb) p *(pthread_mutex_t*)0x72409ba7bf28
$1 = {__data = {__lock = 2, __count = 0, __owner = 350043, __nusers = 1, __kind = 0, __spins = 0, __elision = 0, __list = {__prev = 0x0, __next = 0x0}},
__size = "\002\000\000\000\000\000\000\000[W\005\000\001", '\000' <repeats 26 times>, __align = 2}
(gdb) thread find 350043
Thread 59 has target id 'Thread 0x7240134006c0 (LWP 350043)'
(gdb) thread 59
[Switching to thread 59 (Thread 0x7240134006c0 (LWP 350043))]
#0 0x00007240eb098d61 in __futex_abstimed_wait_common64 (private=29248, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x723f70626b98) at ./nptl/futex-internal.c:57
warning: 57 ./nptl/futex-internal.c: Aucun fichier ou dossier de ce nom
(gdb) bt
#0 0x00007240eb098d61 in __futex_abstimed_wait_common64 (private=29248, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x723f70626b98) at ./nptl/futex-internal.c:57
#1 __futex_abstimed_wait_common (cancel=true, private=29248, abstime=0x0, clockid=0, expected=0, futex_word=0x723f70626b98) at ./nptl/futex-internal.c:87
#2 __GI___futex_abstimed_wait_cancelable64 (futex_word=futex_word@entry=0x723f70626b98, expected=expected@entry=0, clockid=clockid@entry=0, abstime=abstime@entry=0x0, private=private@entry=0) at ./nptl/futex-internal.c:139
#3 0x00007240eb09b7dd in __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x723f70626b48, cond=0x723f70626b70) at ./nptl/pthread_cond_wait.c:503
#4 ___pthread_cond_wait (cond=0x723f70626b70, mutex=0x723f70626b48) at ./nptl/pthread_cond_wait.c:627
#5 0x00007240ec3a4c99 in dhtnet::IceTransport::send(unsigned int, unsigned char const*, unsigned long) () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#6 0x00007240ec3bdd4b in dhtnet::IceSocketEndpoint::write(unsigned char const*, unsigned long, std::error_code&) () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#7 0x00007240ec3d3cbd in dhtnet::tls::TlsSession::TlsSessionImpl::sendRaw(void const*, unsigned long) () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#8 0x00007240ec3d3e2b in dhtnet::tls::TlsSession::TlsSessionImpl::sendRawVec(iovec const*, int) () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#9 0x00007240eae3d9e8 in ??? () at /lib/x86_64-linux-gnu/libgnutls.so.30
#10 0x00007240eae3f410 in ??? () at /lib/x86_64-linux-gnu/libgnutls.so.30
#11 0x00007240eae40f66 in gnutls_record_send2 () at /lib/x86_64-linux-gnu/libgnutls.so.30
#12 0x00007240ec3ce7d2 in dhtnet::tls::TlsSession::TlsSessionImpl::send(unsigned char const*, unsigned long, std::error_code&) () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#13 0x00007240ec3b7466 in dhtnet::MultiplexedSocket::write(unsigned short const&, unsigned char const*, unsigned long, std::error_code&) () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#14 0x00007240ec3b7e8a in dhtnet::ChannelSocket::write(unsigned char const*, unsigned long, std::error_code&) () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#15 0x00007240ec02b806 in jami::GitServer::Impl::sendPackData (this=0x724060119da0) at jamidht/gitserver.cpp:420
#16 0x00007240ec02939d in jami::GitServer::Impl::parseOrder (this=0x724060119da0, buf="") at jamidht/gitserver.cpp:139
#17 0x00007240ec02e0b4 in jami::GitServer::Impl::Impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<dhtnet::ChannelSocket> const&)::{lambda(unsigned char const*, unsigned long)#1}::operator()(unsigned char const*, unsigned long) const
(__closure=0x72400d9e7f40, buf=0x7240a402b4f0 "004dwant e9c8b3c841689508816bc7dd4d66644d36ed0782 side-band-64k include-tag \n00000009done\n\355\353@r", len=90) at jamidht/gitserver.cpp:67
#18 0x00007240ec031490 in std::__invoke_impl<unsigned long, jami::GitServer::Impl::Impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<dhtnet::ChannelSocket> const&)::{lambda(unsigned char const*, unsigned long)#1}&, unsigned char const*, unsigned long>(std::__invoke_other, jami::GitServer::Impl::Impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<dhtnet::ChannelSocket> const&)::{lambda(unsigned char const*, unsigned long)#1}&, unsigned char const*&&, unsigned long&&) (__f=...) at /usr/include/c++/13/bits/invoke.h:61
#19 0x00007240ec0309e3 in std::__invoke_r<long, jami::GitServer::Impl::Impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<dhtnet::ChannelSocket> const&)::{lambda(unsigned char const*, unsigned long)#1}&, unsigned char const*, unsigned long>(jami::GitServer::Impl::Impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<dhtnet::ChannelSocket> const&)::{lambda(unsigned char const*, unsigned long)#1}&, unsigned char const*&&, unsigned long&&) (__fn=...) at /usr/include/c++/13/bits/invoke.h:114
#20 0x00007240ec02f0a5 in std::_Function_handler<long (unsigned char const*, unsigned long), jami::GitServer::Impl::Impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<dhtnet::ChannelSocket> const&)::{lambda(unsigned char const*, unsigned long)#1}>::_M_invoke(std::_Any_data const&, unsigned char const*&&, unsigned long&&) (__functor=..., __args#0=@0x7240133fc378: 0x7240a402b4f0 "004dwant e9c8b3c841689508816bc7dd4d66644d36ed0782 side-band-64k include-tag \n00000009done\n\355\353@r", __args#1=@0x7240133fc380: 90)
at /usr/include/c++/13/bits/std_function.h:290
#21 0x00007240ec3b0bb6 in dhtnet::ChannelSocket::onRecv(std::vector<unsigned char, std::allocator<unsigned char> >&&) () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#22 0x00007240ec3b3e7f in dhtnet::MultiplexedSocket::Impl::handleChannelPacket(unsigned short, std::vector<unsigned char, std::allocator<unsigned char> >&&) ()
at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#23 0x00007240ec3bb03c in dhtnet::MultiplexedSocket::Impl::eventLoop() () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#24 0x00007240ec3bd898 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<dhtnet::MultiplexedSocket::Impl::Impl(dhtnet::MultiplexedSocket&, std::shared_ptr<asio::io_context>, dht::Hash<32ul> const&, std::unique_ptr<dhtnet::TlsSocketEndpoint, std::default_delete<dhtnet::TlsSocketEndpoint> >, std::shared_ptr<dht::log::Logger>)::{lambda()#1}> > >::_M_run() () at /home/ffauteux-chapleau/jami-client-qt/daemon/src/.libs/libjami.so.0
#25 0x00007240eb4ecdb4 in ??? () at /lib/x86_64-linux-gnu/libstdc++.so.6
#26 0x00007240eb09ca94 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:447
#27 0x00007240eb129c3c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78