BUG: Memory-leak on streaming queries when LoadBuffers are not aligned#2936
Merged
rbygrave merged 2 commits intoebean-orm:masterfrom Feb 13, 2023
Merged
BUG: Memory-leak on streaming queries when LoadBuffers are not aligned#2936rbygrave merged 2 commits intoebean-orm:masterfrom
rbygrave merged 2 commits intoebean-orm:masterfrom
Conversation
0e55f7c to
61d6ccc
Compare
Member
|
This change looks good to me.
I'm not sure about other options. My gut says use this weak references approach as you have done here and to me that sounds simpler and likely more robust. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello Rob, unfortunately, we discovered a second problem with memory leaks in streaming queries.
This happens, when LoadBuffers are involved.
Normally the loadBuffer holds references up to
batchSize(default=10) beans. The beans itself holds references to BeanLists, which holds references to the load buffers. This is a cycle, but normally not critical, as there is a cut every batch.If multiple load buffers are involved, we have luck, as long there are correctly aligned and do not "overlap". This overlap may happen if beans have different layouts (e.g. inherited beans)
In the test case, I've created ONE TestModel3A bean here, that has the "many2" property missing.
So when the first "findEach" loads the bean, the
many1property has a buffer of 10 belonging to the beans BBBBBABBB and all of them refer back to the same load context. But inmany2there are 10 A beans and the last bean holds a reference to a different load-context. They all build a "chain", so that they cannot be gc'ed.I've written a test, that fails with -Xmx100m in findEach
@rbygrave How do you think should we fix these issues. Should we introduce weak references in loadContext or do you see other options like skipping the non existent property
many2in TestModel3A, so that the loadcontext will be properly aligned