Bug 161035 - Spinning wheel hang on MacOS when using the Zotero plugin.
Summary: Spinning wheel hang on MacOS when using the Zotero plugin.
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
24.2.3.2 release
Hardware: Other macOS (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:24.8.0 target:24.2.4
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-10 23:58 UTC by Peter N. Steinmetz
Modified: 2024-05-17 22:11 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
test030.odt (23.39 KB, application/vnd.oasis.opendocument.text)
2024-05-11 00:03 UTC, Peter N. Steinmetz
Details
Sample file while spinning is occurring. (166.80 KB, text/plain)
2024-05-13 15:49 UTC, Peter N. Steinmetz
Details
Sample of spinning LibreOffice after one minute (143.91 KB, text/plain)
2024-05-14 15:00 UTC, Peter N. Steinmetz
Details
File which does not spin because bookmark is removed. (22.41 KB, application/vnd.oasis.opendocument.text)
2024-05-14 20:09 UTC, Peter N. Steinmetz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter N. Steinmetz 2024-05-10 23:58:29 UTC
Description:
Trying to insert a citation from Zotero using the LibreOffice Zotero integration causes a spinning wheel to appear. LibreOffice is then hung and must be force quite. Zotero is also hung and must be force quit.

Steps to Reproduce:
1. This starts with a specific type of .odt document which must contain a bookmark. 
2. Try inserting a citation to a Zotero reference just after the bookmark. The cursor will turn to the spinning ball and LibreOffice must be force quit as must Zotero. 
3.

Actual Results:
Pop up of the citation search and insertion bar.

Expected Results:
Spinning wheel and hang. 


Reproducible: Always


User Profile Reset: Yes

Additional Info:
LibreOffice version 24.2.3.2 (AARCH64) does this. 
version 7.6.7.2 (AARCH64) does not. 

Zotero version 7.0.0-beta.77+adaa61f2c
Zotero LibreOffice Integration 6.0.3
MacOS 14.2.1

I can provide a test file if needed. 

Since this depends on the extension, a safe mode test will not work here.
Comment 1 Peter N. Steinmetz 2024-05-11 00:03:30 UTC
Created attachment 194079 [details]
test030.odt

This file does not cause the spin and hang, but does not allow the integration to work. Attempting to insert a citation just does nothing. This is likely related. 

I have a much larger file which causes the hang, but thought I should submit this smaller one first.
Comment 2 Patrick Luby (volunteer) 2024-05-13 00:36:26 UTC
I don't know anything about Zotero, but my first guess is that LibreOffice is caught in a deadlock between two competing threads.

Are you familiar with the Activity Monitor application on macOS? If yes, can you upload a sample of LibreOffice when it is hanging? If no, I can write some steps for you.
Comment 3 Peter N. Steinmetz 2024-05-13 15:49:23 UTC
Created attachment 194103 [details]
Sample file while spinning is occurring.
Comment 4 Patrick Luby (volunteer) 2024-05-13 18:14:04 UTC
Thank you for the sample. From your sample, it looks like LibreOffice might be stuck in loop. I am not very familiar with the Writer code, but from what I can see, during your sample Writer was busy creating a list of all of the chunks of text in your document.

The loop is called from Java code so I wonder if the Zotero extension is reconstructing the entire document. So, can you trigger the hang again and, this time, wait a full minute before taking a sample. This will tell us if we are still in the same loop after a minute has passed or if the looping is elsewhere.
Comment 5 Adomas Venčkauskas 2024-05-14 07:16:04 UTC
This is a regression from 7.6.7.2. We at Zotero have not investigated what specifically in our extension causes it, but we can if that would help with fixing this.
Comment 6 Peter N. Steinmetz 2024-05-14 15:00:48 UTC
Created attachment 194116 [details]
Sample of spinning LibreOffice after one minute

As requested, this is a sample of the LibreOffice process which has been spinning for one minute after attempting to activate the Zotero insert/edit citation command. 

In this case, Zotero also required a force quit afterwards.
Comment 7 Peter N. Steinmetz 2024-05-14 15:05:24 UTC
I will also add a bit more detail here that was also covered in the discussion at Zotero at https://forums.zotero.org/discussion/114299/bug-macos-libreoffice-crash-on-insert-citation#latest

As noted here as well, this does not occur with LibreOffice version 7.6.7.2 for the same test files. 

It only occurs if one tries to insert the citation right after a bookmark entry in the .odt document. If one removes the bookmark, the problem goes away.
Comment 8 Patrick Luby (volunteer) 2024-05-14 18:55:49 UTC
Your latest sample is in the same exact bit of code in the lcl_ExportBkmAndRedline() function as it was in your previous sample. So, I think LibreOffice is blocked and waiting for something (reading a file or network connection?) somewhere in the lcl_ExportBkmAndRedline() function.

I will see if I can somehow find the LibreOffice source code line that matches the memory address in the sample where LibreOffice is stuck.
Comment 9 Peter N. Steinmetz 2024-05-14 20:09:48 UTC
Created attachment 194120 [details]
File which does not spin because bookmark is removed.

I just decided to recheck this. test030.odt does cause the spin. test031.odt, which I just attached and has only the single bookmark in the file removed, does NOT cause the spin. 

Since the spin does not happen with LibreOffice version 7.6 but does with 24.2.3.2, this suggests to me that a change in the code around the point identified in the samples or perhaps before in the parsing and analysis of the bookmarks in the document is causing either LibreOffice to send something which violates the protocol for Zotero or exposes a bug in that protocol on the Zotero end.

The fact that Zotero also is hung and requires a force quit tends toward the latter explanation I think.
Comment 10 Patrick Luby (volunteer) 2024-05-14 20:22:27 UTC
(In reply to Peter N. Steinmetz from comment #9)
> Created attachment 194120 [details]
> File which does not spin because bookmark is removed.
> 
> I just decided to recheck this. test030.odt does cause the spin.
> test031.odt, which I just attached and has only the single bookmark in the
> file removed, does NOT cause the spin. 

Interesting. I was installing the following and just tested both test030.odt and test031.odt in LibreOffice version 24.2.3.2 (AARCH64) to match your setup. Zotero beta is newly installed so I can only select My Library > Unfiled Items > Zotero Quick Start Guide when I click the Add/Edit toolbar button in Writer:

Zotero version 7.0.0-beta.77+adaa61f2c
Zotero LibreOffice Integration 6.0.3

If I put the cursor at the beginning of the paragraph starting with "To simulate", click on the Add/Edit toolbar button, select "Zotero Quick Start Guide" in the Zotero popup window, and press enter, a citation gets inserted in both documents.

The only thing that I have different than you is that I am running macOS Sonoma 
14.4.1.

Is there anything else that I am doing differently than you?
Comment 11 Peter N. Steinmetz 2024-05-14 20:25:24 UTC
Thanks for looking into that Patrick. Yes, very important. You have to place the insertion point just before '{\Numpy version'. That is right after the bookmark.

The bookmark is not visible which made this a dickens to isolate.
Comment 12 Patrick Luby (volunteer) 2024-05-14 20:39:30 UTC
(In reply to Peter N. Steinmetz from comment #11)
> Thanks for looking into that Patrick. Yes, very important. You have to place
> the insertion point just before '{\Numpy version'. That is right after the
> bookmark.
> 
> The bookmark is not visible which made this a dickens to isolate.

Ahah! I can now reproduce the hang with test030.odt with the above steps and it is hanging in the exact same place as your sample.

In my local master build, LibreOffice crashes instead of hanging so I will start debugging that crash first.
Comment 13 Patrick Luby (volunteer) 2024-05-14 22:11:43 UTC
OK. I found what is triggering this bug: it is the following XML snippet in test030.odt's content.xml:

<text:bookmark text:name="__DdeLink__4354_2143787274" />

If I select the View > Navigator menu item and delete this bookmark, no crash in my local master build and no hang in LibreOffice 24.2.3.

So Writer definitely gets stuck in an apparently infinite loop. The only difference in my local master build is that, instead of looping, I enabled debug code and so it crashes when it hits the following assertion:

Assertion failed: (!"Some bookmarks were not consumed earlier"), function lcl_ExportBookmark, file unoportenum.cxx, line 611.

I am not familiar with the code, so I will need to step through the code and see if I can find where the above bookmark derails the exit from the loop.
Comment 14 Peter N. Steinmetz 2024-05-14 23:25:35 UTC
Nice find Patrick. I also found that if I removed that tag from the xml and reconstructed the document that the problem went away. 

Definitely sounds like something in the parser is broken. I wonder if it has to do with the tag just being and open and close tag, with an attribute but no content?
Comment 15 Peter N. Steinmetz 2024-05-14 23:38:41 UTC
A few more hints. 

It will still spin after deleting that bookmark and inserting another one with a different name. 

It spins if you try to insert the citation anywhere AFTER the bookmark, but not before it.
Comment 16 Patrick Luby (volunteer) 2024-05-15 21:10:44 UTC
(In reply to Adomas Venčkauskas from comment #5)
> This is a regression from 7.6.7.2. We at Zotero have not investigated what
> specifically in our extension causes it, but we can if that would help with
> fixing this.

I think I found a fix for this "stuck in an infinite loop" bug. Does Zotero do LibreOffice builds internally? If yes, you can test out my fix by applying the following patch to either a master of libreoffice-24-2 branch build:

https://gerrit.libreoffice.org/c/core/+/167710
Comment 17 Mike Kaganski 2024-05-16 05:38:48 UTC
This *might* be related to commit 1d7ce421480d9170316533de03feb8d04eb5c767 and/or commit 58e79c4394783033f61e1309214d9060e2f0adf2.
Comment 18 Mike Kaganski 2024-05-16 06:12:03 UTC
https://gerrit.libreoffice.org/c/core/+/167720 is my blind take (I *hope* I see the problem that I introduced in commit 1d7ce421480d9170316533de03feb8d04eb5c767, from the code reading - I didn't repro the specific problem here).
Comment 19 Commit Notification 2024-05-16 14:39:52 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/9d3c6b31158aedc33bd616981f0f80af8a0ed1b0

tdf#161035: The previous bookmarks can legitimately be not processed

It will be available in 24.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 20 Commit Notification 2024-05-16 20:41:42 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-24-2":

https://git.libreoffice.org/core/commit/324c1a72961ccc1af1c496689c558aa127ef3d81

tdf#161035: The previous bookmarks can legitimately be not processed

It will be available in 24.2.4.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 21 Patrick Luby (volunteer) 2024-05-16 21:24:27 UTC
Mike Kaganski's fix for this bug should be in tomorrow's (17 May 2024) nightly master builds:

https://dev-builds.libreoffice.org/daily/master/current.html

Note for macOS testers: the nightly master builds install in /Applications/LibreOfficeDev.app. These builds are not codesigned like regular LibreOffice releases so you will need to execute the following Terminal command after installation but before you launch /Applications/LibreOfficeDev:

xattr -d com.apple.quarantine /Applications/LibreOfficeDev.app
Comment 22 Peter N. Steinmetz 2024-05-17 22:07:43 UTC
Daily build for aarch64 is not working on my system so I can't test. I guess I will wait for 24.8.0.
Comment 23 Peter N. Steinmetz 2024-05-17 22:11:56 UTC
Sorry, I guess I can't delete the prior comment, but I see the remark in the email about permissions.