https://bugs.documentfoundation.org/show_bug.cgi?id=174142
Bug ID: 174142
Summary: LOK on Windows: loading any Calc document deadlocks
(SetWindowPos for the Name Box sent to "VCL Main",
which waits for the SolarMutex in
CoWaitForMultipleHandles)
Product: LibreOffice
Version: 25.8.0.0 alpha0+
Hardware: x86-64 (AMD64)
OS: Windows (All)
Status: UNCONFIRMED
Severity: normal
Priority: medium
Component: LibreOffice
Assignee: [email protected]
Reporter: [email protected]
Regression from: 1e2e51607a16 / 6b6f8ca3dd4a (2025-01-10), via the LOK main
thread's apartment (below)
Version field: 25.8.0.0 alpha0+ (tested: 25.8.7.3, 26.2.7.1, 26.8.1.1 affected;
25.2.7.2 works)
A LibreOfficeKit client on Windows (multithreaded mode, no unipoll) hangs in
`documentLoadWithOptions` for every Calc document: .xlsx, .csv and a new blank
`scalc` document.
Writer documents load and render normally in the same process.
Thread dump while hung (cdb, LibreOffice public symbols, 26.8.1.1):
LOK client thread (holds the SolarMutex):
```
win32u!NtUserSetWindowPos
vclplug_winlo!WinSalFrame::SetPosSize
mergedlo!vcl::Window::setPosSizePixel
mergedlo!ImplListBoxFloatingWindow::setPosSizePixel
mergedlo!vcl::Window::SetSizePixel
mergedlo!ComboBox::Resize
...
mergedlo!JSInstanceBuilder::CreateAddressInputBuilder
mergedlo!Application::CreateInterimBuilder
mergedlo!InterimItemWindow::InterimItemWindow
sclo!ScPosWnd::ScPosWnd
sclo!ScInputWindow::ScInputWindow
sclo!ScInputWindowWrapper::ScInputWindowWrapper
mergedlo!SfxChildWindow::CreateChildWindow
...
mergedlo!framework::Desktop::loadComponentFromURL
mergedlo!lo_documentLoadWithOptions
```
"VCL Main" thread (started by lo_startmain):
```
ntdll!NtWaitForMultipleObjects
KERNELBASE!WaitForMultipleObjectsEx
combase!DefaultWaitForHandles
combase!CoWaitForMultipleHandles
sal3!sal::systools::WaitForMultipleObjects_COMDispatch
sal3!osl_waitCondition
vclplug_winlo!osl::Condition::wait
vclplug_winlo!SalYieldMutex::doAcquire
mergedlo!SolarMutexReleaser::~SolarMutexReleaser
mergedlo!VCLXWindowImpl::OnProcessCallbacks
...
mergedlo!Application::Execute
mergedlo!soffice_main
mergedlo!lo_startmain
```
`WinSalYieldMutex::doAcquire` relies on the wait processing sent messages
(tdf#96887 comment:
"we must wait for two things: the yield mutex being unlocked, SendMessage()
being triggered").
Up to 25.2 `osl_waitCondition` used `MsgWaitForMultipleObjects(...,
QS_SENDMESSAGE)`. Since
commits 1e2e51607a16 ("Try to use CoWaitForMultipleHandles magic to handle COM
message loop") and
6b6f8ca3dd4a ("Factor out and simplify COM-safe wait"), both 2025-01-10, it
uses
`CoWaitForMultipleHandles(COWAIT_DISPATCH_CALLS, ...)`, which pumps sent
messages only in a
single-threaded apartment.
In LOK multithreaded mode "VCL Main" is not an STA: `lo_initialize` starts
`lo_startmain` with
`osl_createThread`, whose `oslWorkerWrapperFunction` initialises COM with
`COINIT_MULTITHREADED`.
`SalData::SalData()` then asks for `COINIT_APARTMENTTHREADED` ("put main thread
in Single Threaded
Apartment"), gets `RPC_E_CHANGED_MODE` (`WhenFailed::NoThrow`), and the thread
stays in the MTA.
So `CoWaitForMultipleHandles` does not deliver the `SetWindowPos` sent from the
LOK thread, and both
threads wait for each other. Desktop LibreOffice is not affected because its
main thread is the
process's real main thread.
Confirmed experimentally: patching `vclplug_winlo.dll`'s import of
`CoInitializeEx` so that the STA
request on that thread does `CoUninitialize()` and retries (leaving "VCL Main"
an STA) makes the
Calc load complete on 25.8.7.3 and 26.8.1.1 with the formula bar shown.
Possible fixes: start
`lo_startmain` on a thread that is not put in the MTA, or keep pumping sent
messages in
`osl_waitCondition` when the thread is not an STA.
Steps to reproduce:
1. On Windows, install LibreOffice 25.8.x or later.
2. In a LOK client: `lok_init_2(<program dir>, <profile url>)`, then
`documentLoadWithOptions(<file:///C:/.../any.xlsx>, "")`.
3. The call never returns.
A minimal client and test: `scripts/lok/wos-lok-host.cpp` and
`e2e/lok-host-smoke.mjs` in the
repository above (`node e2e/lok-host-smoke.mjs wos-lok-host.exe "<program
dir>\" "<program dir>\fundamental.ini" file.xlsx`).
Actual result: `documentLoadWithOptions` hangs (tested up to 45 s; a thread
dump shows the deadlock above).
Expected result: The Calc document loads, as in 25.2.7.2.
Workaround: Hiding the formula bar in the user profile
(`/org.openoffice.Office.Views/Windows/26100`, `Visible` = false) avoids this
window and the load
completes. (Calc tiles are then black; see report 2.)
Versions tested (same machine type, clean install each): 25.2.7.2 works;
25.8.7.3, 26.2.7.1, 26.8.1.1 hang.
--
You are receiving this mail because:
You are the assignee for the bug.