Bug 154105 - XCloseBroadcaster: Calc document instance calls XCloseListener::queryClosing AFTER closing the document
Summary: XCloseBroadcaster: Calc document instance calls XCloseListener::queryClosing ...
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
7.4.5.1 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2023-03-09 21:21 UTC by Cesar
Modified: 2023-07-08 02:02 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Sample add-on and testing app (135.24 KB, application/zip)
2023-07-07 14:48 UTC, Cesar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Cesar 2023-03-09 21:21:50 UTC
I'm developing a Calc Add-On (using C++ UNO-API), wich has multiple threads modifying several sheets of an open Calc document.
So, to give a clean exit upon user's closing requests, a component is registered as XCloseListener of the document (the XCloseBroadcaster).  The idea is to veto the close request while any of the Add-On running threads are "bussy" (i.e., producing changes in one or more sheet/s), otherwise, dead-lock conditions are reached (main thread of soffice.bin locks an internal mutex that blocks one or more threads of the Add-On).

Digging, I've found that the XCloseBroadcaster queryes the close (i.e., it calls XCloseListener::queryClosing) AFTER it's closed, so any CloseVetoException thrown by the listener has no effect.

Indeed, the component implementing the XCloseListener interface, also implements XDocumentEventListener interfece.
XDocumentEventListener::XDocumentEventOccured implementation just prints out in console the event occured.
As said before, XCloseListener::queryClosing throws CloseVetoException if at least one of Add-On's threads isn't "iddle". In that case, it also prints out a meesage warning that the close query is vetoed.
Looking at the output, the proble is clear:

[SheetUtilityImpl::documentEventOccured] OnPrepareViewClosing
[SheetUtilityImpl::documentEventOccured] OnPrepareUnload
[SheetUtilityImpl::documentEventOccured] OnModeChanged
[SheetUtilityImpl::documentEventOccured] OnModeChanged
[SheetUtilityImpl::documentEventOccured] OnViewClosed
[SheetUtilityImpl::documentEventOccured] OnUnload
[SheetUtilityImpl::documentEventOccured] OnUnfocus
[SheetUtilityImpl::queryClosing] Vetoing closing (executor/s is/are still running...)

As can be seen, SheetUtilityImpl::queryClosing is called AFTER the OnUnload event (i.e., after the document has been effectively closed).  So, the veto thrown is ignored.

I have tested it only on linux.  Soon I'll test it on Windows.

Is there a cahnce to fix it on next release 7.5.x?
Comment 1 Buovjaga 2023-07-06 12:11:49 UTC
Can you attach an example extension that shows this?
Comment 2 Cesar 2023-07-07 14:48:19 UTC
Created attachment 188253 [details]
Sample add-on and testing app
Comment 3 Buovjaga 2023-07-07 17:30:09 UTC
(In reply to Cesar from comment #2)
> Created attachment 188253 [details]
> Sample add-on and testing app

Thanks. I didn't know exactly what to do so I

1. Installed testCloseVeto/dist/testCloseVeto.oxt
2. Modified testCloseVetoLaunch/dist/runDefault.sh so OFFICE_HOME and PKG_INSTALL_DIR pointed to the correct places

Running runDefault.sh caused a crash and in logdefault.txt I see

warn:io.connector:71657:71657:io/source/connector/connector.cxx:93: Connector : couldn't connect to pipe "uno12081109122261949318019018331151112221168215": 10
warn:io.connector:71657:71657:io/source/connector/connector.cxx:93: Connector : couldn't connect to pipe "uno12081109122261949318019018331151112221168215": 10
warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:904: ignoring modify of unknown set member node ".uno:DeleteRows" in "file:///home/user/libreoffice/instdir/program/../share/registry/res/registry_qtz.xcd"
warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:904: ignoring modify of unknown set member node ".uno:DeleteRows" in "file:///home/user/libreoffice/instdir/program/../share/registry/res/registry_ru.xcd"
warn:io.connector:71657:71657:io/source/connector/connector.cxx:93: Connector : couldn't connect to pipe "uno12081109122261949318019018331151112221168215": 10
warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:904: ignoring modify of unknown set member node ".uno:DeleteRows" in "file:///home/user/libreoffice/instdir/program/../share/registry/res/registry_pl.xcd"
warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:159: bad set node <prop> member in "file:///home/user/libreoffice/instdir/program/../program/../user/uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/lu1xnzi.tmp/Addons_AOO4.xcu"
warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:904: ignoring modify of unknown set member node "ToolBarItems" in "file:///home/user/libreoffice/instdir/program/../program/../user/uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/lu1xnzi.tmp/Addons_AOO4.xcu"
warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:159: bad set node <prop> member in "file:///home/user/libreoffice/instdir/program/../program/../user/uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/lu1xnzh.tmp/Addons.xcu"
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-11-openjdk/lib/libnio.so: /usr/lib/jvm/java-11-openjdk/lib/libnio.so: undefined symbol: reuseport_available
	at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)

and then a huge Java trace.

Any tips?

Arch Linux 64-bit, X11
Version: 24.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 445ab2355333ddb46081baffb8b0e3bb14fe00b3
CPU threads: 8; OS: Linux 6.4; UI render: default; VCL: kf5 (cairo+xcb)
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
Calc: threaded
Built on 7 July 2023
Comment 4 Cesar 2023-07-07 22:58:17 UTC
(In reply to Buovjaga from comment #3)
> (In reply to Cesar from comment #2)
> > Created attachment 188253 [details]
> > Sample add-on and testing app
> 
> Thanks. I didn't know exactly what to do so I
> 
> 1. Installed testCloseVeto/dist/testCloseVeto.oxt
> 2. Modified testCloseVetoLaunch/dist/runDefault.sh so OFFICE_HOME and
> PKG_INSTALL_DIR pointed to the correct places
> 
> Running runDefault.sh caused a crash and in logdefault.txt I see
> 
> warn:io.connector:71657:71657:io/source/connector/connector.cxx:93:
> Connector : couldn't connect to pipe
> "uno12081109122261949318019018331151112221168215": 10
> warn:io.connector:71657:71657:io/source/connector/connector.cxx:93:
> Connector : couldn't connect to pipe
> "uno12081109122261949318019018331151112221168215": 10
> warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:904: ignoring
> modify of unknown set member node ".uno:DeleteRows" in
> "file:///home/user/libreoffice/instdir/program/../share/registry/res/
> registry_qtz.xcd"
> warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:904: ignoring
> modify of unknown set member node ".uno:DeleteRows" in
> "file:///home/user/libreoffice/instdir/program/../share/registry/res/
> registry_ru.xcd"
> warn:io.connector:71657:71657:io/source/connector/connector.cxx:93:
> Connector : couldn't connect to pipe
> "uno12081109122261949318019018331151112221168215": 10
> warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:904: ignoring
> modify of unknown set member node ".uno:DeleteRows" in
> "file:///home/user/libreoffice/instdir/program/../share/registry/res/
> registry_pl.xcd"
> warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:159: bad set node
> <prop> member in
> "file:///home/user/libreoffice/instdir/program/../program/../user/
> uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.
> PackageRegistryBackend/lu1xnzi.tmp/Addons_AOO4.xcu"
> warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:904: ignoring
> modify of unknown set member node "ToolBarItems" in
> "file:///home/user/libreoffice/instdir/program/../program/../user/
> uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.
> PackageRegistryBackend/lu1xnzi.tmp/Addons_AOO4.xcu"
> warn:configmgr:71688:71688:configmgr/source/xcuparser.cxx:159: bad set node
> <prop> member in
> "file:///home/user/libreoffice/instdir/program/../program/../user/
> uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.
> PackageRegistryBackend/lu1xnzh.tmp/Addons.xcu"
> Exception in thread "main" java.lang.UnsatisfiedLinkError:
> /usr/lib/jvm/java-11-openjdk/lib/libnio.so:
> /usr/lib/jvm/java-11-openjdk/lib/libnio.so: undefined symbol:
> reuseport_available
> 	at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
> 
> and then a huge Java trace.
> 
> Any tips?
> 
> Arch Linux 64-bit, X11
> Version: 24.2.0.0.alpha0+ (X86_64) / LibreOffice Community
> Build ID: 445ab2355333ddb46081baffb8b0e3bb14fe00b3
> CPU threads: 8; OS: Linux 6.4; UI render: default; VCL: kf5 (cairo+xcb)
> Locale: fi-FI (fi_FI.UTF-8); UI: en-US
> Calc: threaded
> Built on 7 July 2023

First, you did right using runDefault.sh (redirecting OFFICE_HOME and PKG_INSTALL_DIR).
At least, that is what it was meant to be.
I really don't know what is causing the crash.  I can`t recognize any of the error/warning messages as part of the add-on.
I would search lu1xnzh package at ~/.config/libreoffice/4/user/uno_packages/cache/uno_packages/ to see what extension is complaining. If you can, you might disable it while testing my app.
Alternatively, if you have an application or Calc extension of your own, you might try to create an instance of com.example.TestCloseVeto (just like testCloseVetoLaunch does), and register it as XDocumenrEventListener and XCloseListener of the SpreadsheetDocument instance.