vcl/osx/salinst.cxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
New commits: commit d193d65635de197efe32d97a99540a31a5455c41 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Thu Sep 8 17:30:38 2022 +0200 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Wed Dec 7 11:05:35 2022 +0000 tdf#151894 Pre-init NSSpellCHecker to avoid SolarMutex deadlock Besides the deadlock scenario documented at <https://bugs.documentfoundation.org/show_bug.cgi?id=151894> "FILEOPEN a Base Document with customized event for open a startform by 'open document' LO stuck" there is at least one other known scenario documented at <https://gerrit.libreoffice.org/c/core/+/143565/> "Fix hang during JunitTest_framework_complex on macOS" (which even carries a true fix, for just that one scenario, which wouldn't require this hack). Change-Id: Iafcb39607e71cc3abe46ce762f9c1785a62acfd3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139702 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx index 3512a9a16142..e7f202ae7ae5 100644 --- a/vcl/osx/salinst.cxx +++ b/vcl/osx/salinst.cxx @@ -190,6 +190,28 @@ void AquaSalInstance::AfterAppInit() name: @"AppleRemoteWillResignActive" object: nil ]; #endif + + // HACK: When the first call to [NSSpellChecker sharedSpellChecker] (in + // lingucomponent/source/spellcheck/macosxspell/macspellimp.mm) is done both on a thread other + // than the main thread and with the SolarMutex erroneously locked, then that can lead to + // deadlock as [NSSpellChecker sharedSpellChecker] internally calls + // AppKit`-[NSSpellChecker init] -> + // AppKit`-[NSSpellChecker _fillSpellCheckerPopupButton:] -> + // AppKit`-[NSApplication(NSServicesMenuPrivate) _fillSpellCheckerPopupButton:] -> + // AppKit`-[NSMenu insertItem:atIndex:] -> + // Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] -> + // CoreFoundation`_CFXNotificationPost -> + // Foundation`-[NSOperation waitUntilFinished] + // waiting for work to be done on the main thread, but the main thread is typically already + // blocked (in some event handling loop) waiting to acquire the SolarMutex. The real solution + // would be to fix all the cases where a call to [NSSpellChecker sharedSpellChecker] in + // lingucomponent/source/spellcheck/macosxspell/macspellimp.mm is done while the SolarMutex is + // locked (somewhere up the call chain), but that appears to be rather difficult (see e.g. + // <https://bugs.documentfoundation.org/show_bug.cgi?id=151894> "FILEOPEN a Base Document with + // customized event for open a startform by 'open document' LO stuck"). So, at least for now, + // chicken out and do that first call to [NSSpellChecker sharedSpellChecker] upfront in a + // controlled environment: + [NSSpellChecker sharedSpellChecker]; } SalYieldMutex::SalYieldMutex()