Issues
- Memory leak (SessionImpl) when updating index without transactionHSEARCH-4225Resolved issue: HSEARCH-4225Yoann Rodière
- Null handling for elements in container bridges isn't consistent with non-container bridgesHSEARCH-2663Resolved issue: HSEARCH-2663Yoann Rodière
- @Facet on container (Iterable, Array, ...) properties indexes the container's toString()HSEARCH-2535Resolved issue: HSEARCH-2535Yoann Rodière
- An entity could not be indexed. Gave me java.lang.Object is not an indexed entity or a subclass of an indexed entityHSEARCH-2530Resolved issue: HSEARCH-2530
- Implement support for lucene search_analyzerHSEARCH-2515Resolved issue: HSEARCH-2515Yoann Rodière
- Smarter dirty checking when using @ContainedIn with custom field bridgesHSEARCH-2496Resolved issue: HSEARCH-2496Yoann Rodière
- TikaBridgeProvider does not recognize byte arrays as a compatible typeHSEARCH-2494Resolved issue: HSEARCH-2494Davide D'Alto
- ConnectedMultiFieldsPhraseQueryBuilder uses HashMap on sorted mapHSEARCH-2479Resolved issue: HSEARCH-2479
- Allow Numeric Faceting from FieldBridgeHSEARCH-2446Resolved issue: HSEARCH-2446Yoann Rodière
- Using array/iterable/map field bridges requires the @IndexedEmbedded annotationHSEARCH-2419Resolved issue: HSEARCH-2419Yoann Rodière
Memory leak (SessionImpl) when updating index without transaction
Description
Attachments
Details
Assignee
Yoann RodièreYoann RodièreReporter
Bernhard ScholzBernhard ScholzSprint
NoneFix versions
Affects versions
Priority
Major
Details
Details
Assignee
Reporter
Sprint
Fix versions
Affects versions
Priority
Activity
Yoann RodièreJune 16, 2021 at 3:00 PM
Thanks again for the reproducer; I was able to write a test and to fix the problem. The patch will be applied to Hibernate Search 5.11.10.Final.
Yoann RodièreMay 18, 2021 at 7:08 AM
Hello,
Thanks for reporting this.
First, let me warn you that you are using a very old version of Hibernate Search that is no longer maintained.
That being said, it’s possible that this problem still occurs with Hibernate Search 5.10/5.11, and maybe even 6.0 (though that’s less likely), so we will have a look, and if possible fix the problem in those versions. We will not backport the fix to 5.5.
To answer your questions:
I have to get a closer look to your reproducer to tell if it’s a bug or misuse.
It is not forbidden to update the index outside a transaction, but it’s definitely not recommended. See for details of each mode (outside a transaction/within a transaction).
Using flush() after flushToIndexes() is not normally required, but I’d have to check your particular use case.
Problem
We are observing thousands of already closed
SessionImpl
instances in memory. Some of them have references to large objects (via loadEvent or actionQueue), causing a significant memory consumption.We are using the following pattern to update entities in the index:
This seems to be in line with https://docs.jboss.org/hibernate/search/5.5/reference/en-US/html_single/#search-batchindex-flushtoindexes except that we are not using a transaction. But obviously there is now a hard reference from PostTransactionWorkQueueSynchronization#transactionIdentifier to the
SessionImpl
instance, which will not be GCed any more:According to the following comments, this should never happen:
https://github.com/hibernate/hibernate-search/blob/5.5.5.Final/orm/src/main/java/org/hibernate/search/event/impl/FullTextIndexEventListener.java#L76
https://github.com/hibernate/hibernate-search/blob/5.5.5.Final/orm/src/main/java/org/hibernate/search/event/impl/FullTextIndexEventListener.java#L219
https://github.com/hibernate/hibernate-search/blob/5.5.5.Final/engine/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java#L27
Steps to reproduce
Unpack Maven project
, build and run
MyExample.main()
(in the IDE)-> Output
Enter 's'
Enter 'i'
Perform GC, analyse heap dump (e.g. with Eclipse MAT)
-> Now there should be 0 instances of
SessionImpl
, but instead there is 1 instance with the above Path2GCWorkaround
We found that one of the following approaches will solve the problem for us:
use a transaction while indexing
or call
fullTextSession.flush()
afterfullTextSession.flushToIndexes()
Questions
But there are some questions left:
Is the observed behavior expected or is it a bug that should be fixed?
Is it forbidden to update the index outside a transaction?
Is it required to use
flush()
afterflushToIndexes()
?