desktop/source/lib/init.cxx |    8 ++++++--
 vcl/source/app/svapp.cxx    |    1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

New commits:
commit 57654c90fa61f99453baacdad7f88d41eb55490c
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Jul 22 17:20:20 2025 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Jul 23 14:26:41 2025 +0200

    Don't hold the SolarMutex when calling joinThreads
    
    hold it during flushBufferedVOCs and during vcl::lok::trimMemory
    but don't hold it for joinThreads
    
     Thread 5 (Thread 0x7fa3cf7fe6c0 (LWP 1721249)):
     #0  futex_wait (private=0, expected=2, futex_word=0x1b023690) at 
../sysdeps/nptl/futex-internal.h:146
     #1  __GI___lll_lock_wait (futex=futex@entry=0x1b023690, private=0) at 
./nptl/lowlevellock.c:49
     #2  0x00007fa3ec6ab4da in lll_mutex_lock_optimized (mutex=0x1b023690) at 
./nptl/pthread_mutex_lock.c:48
     #3  ___pthread_mutex_lock (mutex=0x1b023690) at 
./nptl/pthread_mutex_lock.c:128
     #4  0x00007fa3e419eaf6 in osl_acquireMutex () from 
/opt/collaboraoffice/program/libuno_sal.so.3
     #5  0x00007fa3e9e7fa59 in osl::Mutex::acquire (this=0x1b0263a8) at 
/opt/collaboraoffice/debugsource/include/osl/mutex.hxx:63
     #6  SvpSalYieldMutex::doAcquire (this=0x1b0263a0, nLockCount=1) at 
/opt/collaboraoffice/debugsource/vcl/headless/svpinst.cxx:356
     #7  0x00007fa3de30ab73 in comphelper::SolarMutex::acquire (nLockCount=1, 
this=0x1b0263a0) at 
/opt/collaboraoffice/debugsource/include/comphelper/solarmutex.hxx:86
     #8  osl::Guard<comphelper::SolarMutex>::Guard (t=..., this=<synthetic 
pointer>) at /opt/collaboraoffice/debugsource/include/osl/mutex.hxx:144
     #9  SolarMutexGuard::SolarMutexGuard (this=<synthetic pointer>) at 
/opt/collaboraoffice/debugsource/include/vcl/svapp.hxx:1343
     #10 SwXFlatParagraph::isModified (this=0x7fa3d0022d10) at 
/opt/collaboraoffice/debugsource/sw/source/core/unocore/unoflatpara.cxx:236
     #11 0x00007fa3e7f717ec in GrammarCheckingIterator::ProcessResult 
(this=0x1e5d42e0, rRes=..., rxFlatParagraphIterator=..., 
bIsAutomaticChecking=<optimized out>) at 
/opt/collaboraoffice/debugsource/linguistic/source/gciterator.cxx:399
     #12 0x00007fa3e7f7438d in GrammarCheckingIterator::DequeueAndCheck 
(this=0x1e5d42e0) at 
/opt/collaboraoffice/debugsource/linguistic/source/gciterator.cxx:719
     #13 0x00007fa3e41b2563 in osl_thread_start_Impl(void*) () from 
/opt/collaboraoffice/program/libuno_sal.so.3
     #14 0x00007fa3ec6a81f5 in start_thread (arg=<optimized out>) at 
./nptl/pthread_create.c:442
     #15 0x00007fa3ec72889c in clone3 () at 
../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
    
     Thread 1 (Thread 0x7fa3ec61c7c0 (LWP 1719464)):
     #0  __futex_abstimed_wait_common64 (private=128, cancel=true, abstime=0x0, 
op=265, expected=1721249, futex_word=0x7fa3cf7fe990) at 
./nptl/futex-internal.c:57
     #1  __futex_abstimed_wait_common 
(futex_word=futex_word@entry=0x7fa3cf7fe990, expected=1721249, 
clockid=clockid@entry=0, abstime=abstime@entry=0x0, private=private@entry=128, 
cancel=cancel@entry=true) at ./nptl/futex-internal.c:87
     #2  0x00007fa3ec6a4f7b in __GI___futex_abstimed_wait_cancelable64 
(futex_word=futex_word@entry=0x7fa3cf7fe990, expected=<optimized out>, 
clockid=clockid@entry=0, abstime=abstime@entry=0x0, private=private@entry=128) 
at ./nptl/futex-internal.c:139
     #3  0x00007fa3ec6a9ce3 in __pthread_clockjoin_ex 
(threadid=140341537662656, thread_return=0x0, clockid=0, abstime=0x0, 
block=<optimized out>) at ./nptl/pthread_join_common.c:102
     #4  0x00007fa3e7f6d1f6 in GrammarCheckingIterator::TerminateThread 
(this=0x1e5d42e0) at 
/opt/collaboraoffice/debugsource/linguistic/source/gciterator.cxx:310
     #5  0x00007fa3e7f6d23d in GrammarCheckingIterator::joinThreads 
(this=<optimized out>) at 
/opt/collaboraoffice/debugsource/linguistic/source/gciterator.cxx:323
     #6  0x00007fa3e8940aeb in joinThreads 
(eCategory=eCategory@entry=(anonymous 
namespace)::JoinThreads::RESTARTS_ON_DEMAND) at 
/opt/collaboraoffice/debugsource/desktop/source/lib/init.cxx:3581
     #7  0x00007fa3e8940e9f in lo_trimMemory (nTarget=<optimized out>) at 
/opt/collaboraoffice/debugsource/desktop/source/lib/init.cxx:3392
     #8  0x00000000005d9308 in Document::trimIfInactive() ()
     #9  0x0000000000598458 in ChildSession::_handleInput(char const*, int) ()
     #10 0x000000000063476a in Session::handleMessage(std::vector<char, 
std::allocator<char> > const&) ()
     #11 0x00000000005e17b6 in 
Document::forwardToChild(std::basic_string_view<char, std::char_traits<char> >, 
std::vector<char, std::allocator<char> > const&) ()
     #12 0x00000000005e2c88 in Document::drainQueue() ()
     #13 0x00000000005e3372 in KitSocketPoll::kitPoll(int) ()
     #14 0x00007fa3e9e7f1a4 in SvpSalInstance::ImplYield 
(this=this@entry=0x1b00b490, bWait=bWait@entry=true, 
bHandleAllCurrentEvents=bHandleAllCurrentEvents@entry=false) at 
/opt/collaboraoffice/debugsource/vcl/headless/svpinst.cxx:462
    
    Change-Id: I4279eb189c022438924a9f544d4f51295a281e01
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188176
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Ashod Nakashian <a...@collabora.com>
    (cherry picked from commit e410ecaebff1a0453d00ef4f4e3673f38f03cfb9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188200
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index cc507d5dfcfd..ad4bdd739d25 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -167,6 +167,7 @@
 #include <vcl/GestureEventPan.hxx>
 #include <vcl/svapp.hxx>
 #include <unotools/resmgr.hxx>
+#include <tools/debug.hxx>
 #include <tools/fract.hxx>
 #include <tools/json_writer.hxx>
 #include <svtools/ctrltool.hxx>
@@ -3363,6 +3364,7 @@ static int joinThreads(JoinThreads eCategory);
 
 static void flushBufferedVOCs()
 {
+    SolarMutexGuard aGuard;
     // Flush all buffered VOC primitives from the pages.
     SfxViewShell* pViewShell = SfxViewShell::Current();
     if (!pViewShell)
@@ -3387,8 +3389,6 @@ static void flushBufferedVOCs()
 
 static void lo_trimMemory(LibreOfficeKit* /* pThis */, int nTarget)
 {
-    SolarMutexGuard aGuard;
-
     vcl::lok::trimMemory(nTarget);
 
     if (nTarget > 2000)
@@ -3397,6 +3397,8 @@ static void lo_trimMemory(LibreOfficeKit* /* pThis */, 
int nTarget)
 
         // When more aggressively reclaiming memory then shutdown threads which
         // will restart on demand.
+        // The SolarMutex should not be held when calling joinThreads to avoid
+        // deadlock.
         joinThreads(JoinThreads::RESTARTS_ON_DEMAND);
     }
 
@@ -3577,6 +3579,8 @@ static void lo_stopURP(LibreOfficeKit* /* pThis */,
 
 static int joinThreads(JoinThreads eCategory)
 {
+    DBG_TESTNOTSOLARMUTEX();
+
     comphelper::ThreadPool &pool = 
comphelper::ThreadPool::getSharedOptimalPool();
     if (!pool.joinThreadsIfIdle())
         return 0;
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index 92dc319f1f75..124dc4289f29 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -1789,6 +1789,7 @@ void trimMemory(int nTarget)
 {
     if (nTarget >= 1000)
     {
+        SolarMutexGuard aGuard;
         ImplSVData* pSVData = ImplGetSVData();
         if (!pSVData) // shutting down
             return;

Reply via email to