LoayGhreeb / jabref

Graphical Java application for managing BibTeX and biblatex (.bib) databases
https://devdocs.jabref.org
MIT License
0 stars 0 forks source link

BackgroundTask interrupted when shutting down JabRef #6

Open LoayGhreeb opened 1 month ago

LoayGhreeb commented 1 month ago

I want to close the Lucene IndexWriter when the library is closed or when JabRef shuts down. The index should be closed in the background because writing commits to the disk takes time.

Which method should be used for submitting background tasks? All Lucene indexing runs in the background using org.jabref.gui.util.BackgroundTask, but for closing the index, I used org.jabref.logic.util.HeadlessExecutorService.

Stack trace ``` [pool-2-thread-3] org.jabref.logic.search.indexing.DefaultLinkedFilesIndexer.optimizeIndex() WARN: Could not force merge segments.: java.nio.channels.ClosedChannelException at java.base/sun.nio.ch.FileLockImpl.release(FileLockImpl.java:58) at java.base/java.nio.channels.FileLock.close(FileLock.java:336) at org.apache.lucene.core@9.11.0/org.apache.lucene.store.NativeFSLockFactory$NativeFSLock.close(NativeFSLockFactory.java:195) at org.apache.lucene.core@9.11.0/org.apache.lucene.util.IOUtils.close(IOUtils.java:85) at org.apache.lucene.core@9.11.0/org.apache.lucene.util.IOUtils.close(IOUtils.java:72) at org.apache.lucene.core@9.11.0/org.apache.lucene.index.IndexWriter.rollbackInternalNoCommit(IndexWriter.java:2559) at org.apache.lucene.core@9.11.0/org.apache.lucene.index.IndexWriter.rollbackInternal(IndexWriter.java:2464) at org.apache.lucene.core@9.11.0/org.apache.lucene.index.IndexWriter.maybeCloseOnTragicEvent(IndexWriter.java:5774) at org.apache.lucene.core@9.11.0/org.apache.lucene.index.IndexWriter.doFlush(IndexWriter.java:4321) at org.apache.lucene.core@9.11.0/org.apache.lucene.index.IndexWriter.flush(IndexWriter.java:4255) at org.apache.lucene.core@9.11.0/org.apache.lucene.index.IndexWriter.forceMerge(IndexWriter.java:2128) at org.jabref@100.0.0/org.jabref.logic.search.indexing.DefaultLinkedFilesIndexer.optimizeIndex(DefaultLinkedFilesIndexer.java:332) at org.jabref@100.0.0/org.jabref.logic.search.indexing.DefaultLinkedFilesIndexer.lambda$close$5(DefaultLinkedFilesIndexer.java:344) at org.jabref@100.0.0/org.jabref.gui.util.BackgroundTask$2.call(BackgroundTask.java:91) at org.jabref@100.0.0/org.jabref.gui.util.BackgroundTask$2.call(BackgroundTask.java:88) at org.jabref@100.0.0/org.jabref.gui.util.UiTaskExecutor$1.call(UiTaskExecutor.java:173) at javafx.graphics@22.0.1/javafx.concurrent.Task$TaskCallable.call(Task.java:1399) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) at java.base/java.lang.Thread.run(Thread.java:1583) ```

@koppor, please take a look when you are available. Refs: https://github.com/JabRef/jabref-issue-melting-pot/issues/443

koppor commented 3 weeks ago

https://github.com/jobrunr/jobrunr could be tried as another framework 😅🙈. Refs https://github.com/JabRef/jabref-issue-melting-pot/issues/460

koppor commented 3 weeks ago

I want to close the Lucene IndexWriter when the library is closed or when JabRef shuts down. The index should be closed in the background because writing commits to the disk takes time.

And it is OK to not show any progress in the UI?

As far as I understand the PR https://github.com/JabRef/jabref/pull/11385, there was some renaming to distinguish between UI and nonUI (called "headless").

As far as I understand your options and pros and cons, I think, calling HeadlessExecutorService is the right choice? We accept that no progress is shown in the UI. Nevertheless, there should be a LOGGER.info be called at the start and at the end. Sometimes, JabRef hangs during exiting (refs https://github.com/JabRef/jabref/pull/11430) and it should be "easy" to trace which component hangs.